Advertisement
csaki

list.contain meg ctrl R+M

Dec 5th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace listásegyebes
  7. {
  8.     class Program
  9.  
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             while (true)
  14.             {
  15.                 Random rand = new Random();
  16.                 List<int> lista = new List<int>(); // ez egy int lista, amit használhatok tömbként
  17.                 feltöltés(rand, lista);
  18.                 int t = bekérés();
  19.                 ifcontains(lista, t);
  20.                 Console.ReadLine();
  21.             }
  22.         }
  23.  
  24.         private static int bekérés()
  25.         {
  26.             Console.WriteLine("Milyen számot keresel?");
  27.             int t = int.Parse(Console.ReadLine());
  28.             return t;
  29.         }
  30.  
  31.         private static void ifcontains(List<int> lista, int t)
  32.         {
  33.             if (lista.Contains(t))
  34.             {
  35.                 Console.WriteLine("Van benne {0}!", t);
  36.             }
  37.             else
  38.             {
  39.                 Console.WriteLine("Nincs benne {0}!", t);
  40.             }
  41.         }
  42.  
  43.         private static void feltöltés(Random rand, List<int> lista)
  44.         {
  45.             for (int i = 0; i < 20; i++)
  46.             {
  47.                 lista.Add(rand.Next(15));
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement