Advertisement
ntamas

listaelem hozzáadása/törlése/rendezése stb.

Jan 27th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.   class Program
  9.   {
  10.     static void Main(string[] args)
  11.     {
  12.       List<int> lista = new List<int>();
  13.       Random vel = new Random();
  14.       int j = 0;
  15.       while (j < 20)
  16.       {
  17.         int num = vel.Next(10, 100);
  18.         if (!lista.Contains(num))
  19.         {
  20.           lista.Add(num);
  21.           j++;
  22.         }
  23.       }
  24.       /*for(int i = 0; i < 20; i++)
  25.       {
  26.         lista.Add(vel.Next(10, 100));  
  27.       }*/
  28.       for (int i = lista.Count - 1; i >= 0; i--)
  29.       {
  30.         if (lista[i] % 2 != 0)
  31.         {
  32.           lista.RemoveAt(i);
  33.         }
  34.       }
  35.       lista.Sort();
  36.       lista.Insert(0, 123);
  37.       foreach (int i in lista)
  38.       {
  39.         Console.Write("{0} ", i);
  40.       }
  41.       Console.WriteLine("\nMin = {0}\nMax = {1}\nOsszeg = {2}\nAtlag = {3}", lista.Min(), lista.Max(), lista.Sum(), (double)lista.Average());
  42.       Console.ReadKey();
  43.     }
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement