I have the following code:
DataGridModel[] raport = new DataGridModel[100];
... // more code here, nothing relevant
raport[i].populate(param1,param2); // NullReferenceException occurs here
My DataGridModel class has an empty constructor, so nothing is really done there.
When I watch the raport variable, it contains 100 times null, but why? Cause I initialized it with new DataGridModel[100].
If I lose the array of objects in the first line (so only 1 instance), the code works great.
I don’t get it why they are null. Any help?
You initialized it with
new DataGridModel[100], which creates an instance — but it’s an instance of an array that contains 100nullelements.I’m not sure what you mean by
raport.populate– I suppose it’s an extension method? – but here’s how you can solve your problem: