G
Guest
The following code only works as expected if a delay is introduced. As is all
values in the ArrayList are the same. I've tried using other types of
collections, can anyone explain what is happening and is it by design?
using System;
using System.Collections;
namespace CollectionTest
{
public class Bet
{
public ArrayList Selection = new ArrayList();
public Bet()
{
Random x = new Random();
Selection.Add(x.NextDouble());
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
ArrayList Bets = new ArrayList();
// construct some bets
for(int x=0; x<10; x++)
{
Bet b = new Bet();
Bets.Add(b);
//System.Threading.Thread.Sleep(10);
}
foreach(Bet b in Bets)
{
Console.WriteLine(b.Selection[0].ToString());
}
Console.ReadLine();
}
}
}
values in the ArrayList are the same. I've tried using other types of
collections, can anyone explain what is happening and is it by design?
using System;
using System.Collections;
namespace CollectionTest
{
public class Bet
{
public ArrayList Selection = new ArrayList();
public Bet()
{
Random x = new Random();
Selection.Add(x.NextDouble());
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
ArrayList Bets = new ArrayList();
// construct some bets
for(int x=0; x<10; x++)
{
Bet b = new Bet();
Bets.Add(b);
//System.Threading.Thread.Sleep(10);
}
foreach(Bet b in Bets)
{
Console.WriteLine(b.Selection[0].ToString());
}
Console.ReadLine();
}
}
}