Strange C# problem, any ideas?

I am attempting to create an array of objects of type "Creature",

so I decalre an array of type Creature as following:

Creature[] creatures = new Creature[50];

and then use a "for" statement to step through the array and fill it with new elements of type Creature ex.:

for (int i = 0; i < creatures.Length; i++)

{

creatures[i] = new Creature();

}

the problem is that instead of each "Creature" in the array being a different object they all seem to be a reference to the same object, but when I set a breakpoint on the "creatures[i] = new Creature();" line of the for loop and manually step through the code, then it works correctly and each object is different (I get differing behavior in debug mode). Anyone have a take on this? (not really expecting a solution here)

Update:

cd4017, that must be it, since I am using a random number in my constructor, not enough time is elapsing, thank you very much

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 QUIZLS.COM - All rights reserved.