【发布时间】:2014-07-20 20:03:00
【问题描述】:
代码:
Private ingredientProperties(,) As Integer = {{ingredient1.Location.X, ingredient1.Location.Y}, {ingredient1.Size.Width, ingredient1.Size.Height}} ' {{ingredient location X, Y}, {ingredient size X, Y}}
Private amountProperties(,) As Integer = {{amount1.Location.X, amount1.Location.Y}, {amount1.Size.Width, amount1.Size.Height}} ' {{amount location X, Y}, {amount size X, Y}}
在这里,我在类范围内声明两个二维数组,其中包含两个文本框的位置和大小。我很确定我收到了这个错误:
Recipe Manager.exe 中出现“System.InvalidOperationException”类型的未处理异常 附加信息:创建表单时出错。有关详细信息,请参阅 Exception.InnerException。错误是:对象引用未设置为对象的实例。
因为位置和大小还不存在,有没有其他的方法来声明它们?
【问题讨论】:
-
其他选项初始化后为什么不初始化数组呢?以前尝试这样做没有任何意义。你想完成什么?
-
我需要将数组的范围作为我的整个班级,如果我在 Form_Load 事件处理程序中这样做,那么班级的其余部分将无法访问它跨度>
-
范围由声明决定,而不是由初始化决定。例如。如果您的班级中只有
Private ingredientProperties(,) As Integer行,然后在您的Form_Load中执行ingredientProperties = {{ingredient1.Location.X, ingredient1.Location.Y}, {ingredient1.Size.Width, ingredient1.Size.Height}},则该变量已初始化,并且可以按照您的需要访问它。
标签: arrays vb.net controls scope multidimensional-array