I have seen this tactic used often in javascript, and it won't work in C#. Can someone explain why its not working as intended, i think the code should be self explanitory
I am getting an error that the object at index 1 has not been instantiated. Basically, it is creating a new object at index 0, then incrementing the variable, and i want it to do the incrementing first. Is there a way to do this on one line?
Thanks in advance.
Code:
MyObject[] objects= new MyObject[2];
int objIndex = 0;
objects[objIndex] = new MyObject();
objects[objIndex].someAttribute = "attr value";
objects[(objIndex++)] = new MyObject();
//Error occurs below that object hasn't been instantiated
objects[objIndex].someAttribute = "other attr value";
I am getting an error that the object at index 1 has not been instantiated. Basically, it is creating a new object at index 0, then incrementing the variable, and i want it to do the incrementing first. Is there a way to do this on one line?
Thanks in advance.