我对 VB.NET 有点陌生。我需要在数组中保存一种特殊类型的数据。然后我在其他子例程中使用数据。我编写了以下代码作为示例来询问我的问题。
在其他方法中打印或显示数组中的数据时,它没有给出我之前设置的正确值!这可能是什么原因。我需要更改什么来解决问题?
Public Class Form1
Private eList = New List(Of Boolean) From {True, True, True, False}
Private eType = New List(Of String) From {"a1", "a2", "b1", "z"}
Dim Dizi(0 To 1, 0 To 3) As ITEM
Friend ITEM As ITEM
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim iA As ITEM = New ITEM
For i = 0 To 3
Dizi(0, i) = New ITEM
Dizi(1, i) = New ITEM
Next
For i = 0 To 3
iA.Enable = eList(i)
iA.Type = eType(i)
Dizi(0, i) = iA
' iA = Dizi.GetValue(0, i) ' this for checking the setted value on the array cell.
Next
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
For i = 0 To 3
Dizi(1, i) = Dizi(0, i)
Next
Debug.Print(Dizi(0, 2).Type & " " & Dizi(1, 2).Type)
End Sub
End Class
Class ITEM
Property Enable As Boolean
Property Type As String
End Class