P
philip
hello, i am confused with the following code, i suppose i will get 5
numbers in the following code, but i always get 3 numbers, would u
please tell me why? thanks.
List<int> a = new List<int>();
a.Add(1);
a.Add(2);
a.Add(3);
a.Add(4);
a.Add(5);
a.Add(6);
a.Add(7);
a.Add(8);
a.Add(9);
a.Add(10);
List<int> b = new List<int>();
for(int i=0; i<5;i++){
Thread.Sleep(10);
Random randrom = new
Random(unchecked((int)DateTime.Now.Ticks));
int randomNumber = randrom.Next(0, 5);
if (!b.Contains(a[randomNumber]))
{
b.Add(a[randomNumber]);
i++;
}
else
i--;
}
foreach (int i in b)
Console.WriteLine(i);
numbers in the following code, but i always get 3 numbers, would u
please tell me why? thanks.
List<int> a = new List<int>();
a.Add(1);
a.Add(2);
a.Add(3);
a.Add(4);
a.Add(5);
a.Add(6);
a.Add(7);
a.Add(8);
a.Add(9);
a.Add(10);
List<int> b = new List<int>();
for(int i=0; i<5;i++){
Thread.Sleep(10);
Random randrom = new
Random(unchecked((int)DateTime.Now.Ticks));
int randomNumber = randrom.Next(0, 5);
if (!b.Contains(a[randomNumber]))
{
b.Add(a[randomNumber]);
i++;
}
else
i--;
}
foreach (int i in b)
Console.WriteLine(i);