【发布时间】:2012-01-12 09:11:16
【问题描述】:
我有以下代码:
DataGridModel[] raport = new DataGridModel[100];
... // more code here, nothing relevant
raport[i].populate(param1,param2); // NullReferenceException occurs here
我的DataGridModel 类有一个空的构造函数,所以那里什么也没做。
当我查看raport 变量时,它包含100 次null,但为什么呢?因为我用new DataGridModel[100]初始化它。
如果我丢失了第一行中的对象数组(所以只有一个实例),代码效果很好。
我不明白为什么它们为空。有什么帮助吗?
【问题讨论】:
-
你的意思是
raport[x].populate(param1, param2)? -
@kendfrey 是的,这就是我在我的代码中使用它的方式,我只是复制错了 :) 抱歉。
标签: c# oop class nullreferenceexception