0

我不知道我正在尝试做的事情的确切名称……基本上我正在尝试创建一个包含多个属性的对象。每个对象都是独一无二的。以下是我到目前为止所拥有的..

Public Class TestingProperties

    Private m_TestId As Integer
    Public Property TestId() As Integer
        Get
            Return m_TestId
        End Get
        Set(ByVal value As Integer)
            m_TestId = value
        End Set
    End Property

    Private m_TestName As String
    Public Property TestName() As String
        Get
            Return m_TestName
        End Get
        Set(ByVal value As String)
            m_TestName = value
        End Set
    End Property

End Class

那么我下面的内容基本上就是上面的每个对象中包含的属性...

    Dim x As TestingProperties
    x = New TestingProperties
    x.TestName = "N/A"
    x.TestName = "Name1"
    x.TestName = "Name2"
    x.TestId = "0"
    x.TestId = "1"
    x.TestId = "2"

显然这不起作用,因为最后一个 testId 和最后一个 TestName 会覆盖对象属性中包含的所有内容。一旦我弄清楚了,数据将通过 SQL 存储过程提供,但格式应该仍然相似......这个壮举中的任何想法我应该很久以前就学会了。

4

1 回答 1

4
    Dim x As New List(Of TestingProperties)

    For i = 0 To 9
        Dim newx As New TestingProperties
        newx.TestId = i
        newx.TestName = "Name " & i
        x.add(newx)
    Next

现在你有 10 个独特的属性。您可以像这样访问它们:

Console.WriteLine(x(0).TestId)
于 2012-12-07T00:39:00.767 回答