Hi
Bit new to c#.
Need to know how to name an object dynamically?
Something like this…
for (int a=0; a < 10; a++){
for (int b=0; b < 10; b++){
Class Obj[ab] = new Class ();
}
}
thanks
Hi
Bit new to c#.
Need to know how to name an object dynamically?
Something like this…
for (int a=0; a < 10; a++){
for (int b=0; b < 10; b++){
Class Obj[ab] = new Class ();
}
}
thanks
Typically you would use a container of some sort. For example, in this case you could use a 2-d array, in which case the line of code in question would look like this:
Obj[a, b] = new Class();
// I figured you might also be curious how to actually declare the array! Here’s what you’re aiming for.
// Note, as in Jesse’s code, this creates a rectangular array. There are other alternatives.
//
// Good luck with your program.
const int size = 10;
Class[,] Object = new Class[size,size];
for (int i=0; i < size; i++) {
for (int j=0; j < size; j++) {
Object[i,j] = new Class();
}
}