G
Guest
I use Visual Studio .NET 2002 for developing such a program
(...
public Population(int quantity, int gntpLength
currentPop = new Person[quantity]
for (int i = 0; i < quantity; i++
currentPop = new Person(gntpLength)
// * Console.WriteLine(currentPop.ToString() + "\n")
(...
This is a constructor of Population class, where currentPop is its field (Person[] currentPop; - a reference to an array of Person objects). The constructor of Person class returns a Person instance, which is everytime different (this is because I use Random.Next() method to create Person objects). But when I create an array of Person objects in the way above (without the line marked (*)), every instance of Person in the array is the same. It looks like Person constructor would be called only once (instead of 'quantity' number of times). However, when I added the marked line everything was fine - every instance of Person in currentPop array was different. Why it so happens
In addition when I debugged the program and executed it line by line (even without the marked line) it worked OK. But when I set the breakpoint after creating the 'currentPop' array it was wrong. Does it happen because of setting some compiling option or maybe a compiler isn't working fine? Please help me understand why it so happens. Thanks in advance.
(...
public Population(int quantity, int gntpLength
currentPop = new Person[quantity]
for (int i = 0; i < quantity; i++
currentPop = new Person(gntpLength)
// * Console.WriteLine(currentPop.ToString() + "\n")
(...
This is a constructor of Population class, where currentPop is its field (Person[] currentPop; - a reference to an array of Person objects). The constructor of Person class returns a Person instance, which is everytime different (this is because I use Random.Next() method to create Person objects). But when I create an array of Person objects in the way above (without the line marked (*)), every instance of Person in the array is the same. It looks like Person constructor would be called only once (instead of 'quantity' number of times). However, when I added the marked line everything was fine - every instance of Person in currentPop array was different. Why it so happens
In addition when I debugged the program and executed it line by line (even without the marked line) it worked OK. But when I set the breakpoint after creating the 'currentPop' array it was wrong. Does it happen because of setting some compiling option or maybe a compiler isn't working fine? Please help me understand why it so happens. Thanks in advance.