本文介绍了列表内列表。那可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个列表中的一个属性将是其他列表,是否可用?



我正在尝试类似:



I need that one property of a list will be other list, is posible??

I am trying something like:

Public Class List1
        Private _aaaa As String
        Private _bbbb As String
        Private _dddd As List2
        Public Property aaaa() As String
            Get
                Return _aaaa
            End Get
            Set(ByVal value As String)
                _aaaa = value
            End Set
        End Property
        Public Property bbbb() As String
            Get
                Return _bbbb
            End Get
            Set(ByVal value As String)
                _bbbb = value
            End Set
        End Property
        Public Property dddd As List2
            Get
                Return _dddd
            End Get
            Set(ByVal value As List2)
                _dddd = value
            End Set
        End Property
End Class

Public Class List2
        Private _eeee As Integer
        Private _ffff As String
        Public Property _eeee As Integer
            Get
                Return _eeee
            End Get
            Set(ByVal value As Integer)
                _eeee = value
            End Set
        End Property
        Public Property ffff As String
            Get
                Return _ffff
            End Get
            Set(ByVal value As String)
                _ffff = value
            End Set
        End Property
End Class


Public Class List1
        Inherits List(Of List1)
End Class
Public Class List2
        Inherits List(Of List2)
End Class





但是当我尝试对List2充电时,我得到一个例外空值,因为List2未初始化





But when try to charge the List2 i get one exception "null value" because List2 is not initialitated

For I = 0 To 6

     For X = 0 To 5
          Lista1(I).List2(X).eeee = 1
          Lista1(I).List2(X).ffff = 1
     Next

Next





我做错了什么?



What am i doing wrong?

推荐答案

Public Class List1
        Private _aaaa As String
        Private _bbbb As String
        Private _dddd As List2 = New List2
        Public Property aaaa() As String
            Get
                Return _aaaa
            End Get
            Set(ByVal value As String)
                _aaaa = value
            End Set
        End Property
        Public Property bbbb() As String
            Get
                Return _bbbb
            End Get
            Set(ByVal value As String)
                _bbbb = value
            End Set
        End Property
        Public Property dddd As List2
            Get
                Return _dddd
            End Get
            Set(ByVal value As List2)
                _dddd = value
            End Set
        End Property
End Class


Dim Lst As Lista1
For I = 0 To 6
     For X = 0 To 5
          Lista1(I).List2(X).eeee = 1
          Lista1(I).List2(X).ffff = "pP"
     Next
Next





但现在错误是ArgumentoutofrangeException。错误在Lista1(I)中。 List2(X) .eeee = 1



你知道为什么吗?谢谢!!



but now the error is ArgumentoutofrangeException. The error is in Lista1(I).List2(X).eeee =1

Do you know why? Thx again!!


这篇关于列表内列表。那可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:06