I am a rookie to C# and here is my question
class myClass
{
int start;
int end;
.......
}
class program
{
public void main()
{
myClass[] a= new myClass[10];
for (int i = 1; i < a.length; i++)
{
myClass b = new myClass();
a[i] = b;
a[i].start = 1;
... (keep populating)
...
}
console.writeline(a[1].start) // NO PROBLEM WITH THIS LINE, THE VALUE WAS OUTPUTED
subMethod(a);
}
public void subMethod(myClass[] a)
{
console.write(a[1].start); // NO PROBLEM WITH THIS LINE, OUTPUT NORMALLY
for (int i = 1; i < a.length, i++)
{
int h = a[i].start; ????? OBJECT NOT INSTANTIATED
}
}
}
The error is as indicated above and I have difficulty to understand it. Anyone can help me out. Thanks in advance
Please post code that compiles. The error is probably in your transcribing of the code, because this code works perfectly fine: