本文介绍了如何在vb中访问列表类成员和属性的列表类.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在vb中访问列表类成员和属性的列表类.在下面的代码中,我将字符串传递给A类,以及如何传递得到classB成员(mylist)的值而且我想访问classC成员(mystr) 还 ????
How to Access the list class of list class member and property in vb. In below code, I'm passing the string in class A and How to get value of classB member ( mylist ) and i want to access classC member (mystr) also ????
public Class Form1
public sub method1()
textstr = textbox1.Text
Dim str As New ClassA( textstr )
''// here i want to get the data of classB and classC Member mystr data
''// How to do that ??
End sub
End Class
'''----------------------------ClassA-------------------------'''
public class ClassA
private liststr As list(Of classB)
public sub new(byval str As String )
--------
----
liststr.Add(new ClassB(str))
End sub
public Readonly Property _Mylist As List(of classB)
Get
return liststr
End Get
End property
End class
'''----------------------------ClassB-------------------------'''
public class classB
private mylist As new List(of calssC)
public sub new(byval liststr as string )
dim splitstr() As String = liststr.Split("#")
for I As Int32 = 0 to splitstr.count -1
mylist.Add(new classC(splitstr(I)))
Next
End sub
public Readonly Property _Mylist As List(of classC)
Get
return mylist
End Get
End property
End class
'''----------------------------ClassC-------------------------'''
public sub classC
private mystr As String
public sub new( Byval str As String )
mystr = str+""
End class
public Readonly Property _Mystr As String
Get
return mystr
End Get
End property
End Class
推荐答案
如何在vb中访问列表类成员和属性的列表类.
How to Access the list class of list class member and property in vb.
尝试一下:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
method1()
End Sub
Public Sub method1()
Dim textstr As String = TextBox1.Text
Dim str As New ClassA(textstr)
MsgBox(str._Mylist(0)._Mylist(0)._Mystr)
End Sub
End Class
Public Class ClassA
Private liststr As New List(Of classB)
Public Sub New(ByVal str As String)
liststr.Add(New classB(str))
End Sub
Public ReadOnly Property _Mylist As List(Of classB)
Get
Return liststr
End Get
End Property
End Class
Public Class classB
Private mylist As New List(Of classC)
Public Sub New(ByVal liststr As String)
Dim splitstr() As String = liststr.Split("#")
For I As Int32 = 0 To splitstr.Count - 1
mylist.Add(New classC(splitstr(I)))
Next
End Sub
Public ReadOnly Property _Mylist As List(Of classC)
Get
Return mylist
End Get
End Property
End Class
Public Class classC
Private mystr As String
Public Sub New(ByVal str As String)
mystr = str + ""
End Sub
Public ReadOnly Property _Mystr As String
Get
Return mystr
End Get
End Property
End Class
这篇关于如何在vb中访问列表类成员和属性的列表类.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!