I'm making a raffle c# program where random of 1-10 numbers will be drawn and put it on ArrayList and if the number is already drawn then it should not be place in the array...my problem is even if I validate it, it still added on the array.
Here is my code:
Console.WriteLine("RAFFLES");
ArrayList array = new ArrayList();
Random rnd = new Random();
ret: Console.Write("Press 1 to draw");
int draw = int.Parse(Console.ReadLine());
switch(draw)
{
case 0: break;
case 1:
if (array.Contains(rnd.Next(1, 11)))
{
Console.WriteLine("Already Exist");
}
else
array.Add(rnd.Next(1, 11));
goto ret;
case 2:
foreach (var a in array)
Console.WriteLine(a);
break;
}
Aucun commentaire:
Enregistrer un commentaire