CODE:VB.NET數組顯式聲明的問題
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}}
這裏我聲明中包含的位置和兩個文本框的大小類範圍內兩個2 d數組的。我很確定我得到這個錯誤:
An unhandled exception of type 'System.InvalidOperationException' occurred in Recipe Manager.exe Additional information: An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
因爲位置和大小不存在,有沒有其他方式來聲明它們?
爲什麼不您在初始化其他選項後初始化數組?以前嘗試做它沒有任何意義。你想達到什麼目的? – Jens
我需要數組的範圍是我的整個類,如果我在** Form_Load **事件處理程序中執行,那麼它不能由類的其餘部分訪問 – ohSkittle
範圍由聲明決定,而不是由初始化。例如。如果您的類中只有'Private ingredientsProperties(,)As Integer',然後執行'ingredientProperties = {{ingredient1.Location.X,ingredient1.Location.Y},{ingredient1.Size.Width,ingredient1.Size。在你的Form_Load中,這個變量被初始化,並且可以像你想要的那樣訪問它。 – Jens