我有Class ABC
。我想写两个属性
它。我在代码中已经提到了一个。另一个是single dimensional array
。
Public Class ABC
Private m_Type As String
Private SomeArray........need to write a property for array which will be of type `int`
Public Property Type() As String
Get
Return m_Type
End Get
Set(ByVal value As String)
m_Type = value
End Set
End Property
End Class
我不确定如何为可以在List(Of ABC)
中使用的数组定义属性。数组的属性可以是只读数组,因为我将
对其进行硬编码。
所以基本上当我这样做时,
Dim SomeList As New List(Of ABC)
在for循环中我需要这样的东西,
SomeList.Item(index).SomeArray......this will give me all the items inside the array
答案 0 :(得分:2)
您可以使用与声明其他属性类型相同的方式声明数组属性:
Public Class ABC
Private _Type As String
Private _SomeArray As Int32()
Public Property SomeArray As Int32()
Get
Return _SomeArray
End Get
Set(ByVal value As Int32())
_SomeArray = value
End Set
End Property
Public Property Type() As String
Get
Return _Type
End Get
Set(ByVal value As String)
_Type = value
End Set
End Property
End Class
例如,如果要在列表的一个数组中循环所有Integers
:
Dim index As Int32 = 0
Dim someList As New List(Of ABC)
For Each i As Int32 In someList(index).SomeArray
Next
答案 1 :(得分:0)
如果你不打算在获取和集合中做任何特殊的事情,你可以稍微简化你的代码,如下所示(它将只读数组初始化为包含数字1,2,3和4) ):
Public Class ABC
Public Property Type As String
Public ReadOnly Property SomeArray As Integer() = {1,2,3,4}
End Class