한 게시물에 3 개의 게시물이있는 포럼이 있다고 가정 해 보겠습니다.하위 컬렉션이있는 컬렉션
Dim MyFourm As new Fourm
MyFourm.Thread.Add(545)''for ex 545 mean Thread ID.
MyForum.Thread(0).Post(1).Username
스레드가 정수 (= 스레드 ID)의 수집 올리기이
사전을 사용하려는 해달라고 * 포스트 타입 수집해야해야한다 :
나는이 최종 결과를 얻으려면 따라서이 경우 코드는 "첫 번째 스레드를 선택하고 두 번째 게시물을 선택하고이 게시물을 작성한 사용자의 사용자 이름을 검색합니다"라고 말합니다.
조금 연주 후, 나는이 코드 쓰기 : 잘 작동
Public Class MainFrm
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim MyForum As New Forum
MyForum.Thread.Add(500)' some id's
MyForum.Thread.Add(120)
MyForum.Thread(0).Posts.Add(New ForumPost() With {.PostContent = "Therad ID: 500 | Post: 1#", .Username = "Don"})
MyForum.Thread(0).Posts.Add(New ForumPost() With {.PostContent = "Therad ID: 500 | Post: 2#", .Username = "Shon"})
MyForum.Thread(0).Posts.Add(New ForumPost() With {.PostContent = "Therad ID: 500 | Post: 3#", .Username = "Ron"})
MyForum.Thread(1).Posts.Add(New ForumPost() With {.PostContent = "Therad ID: 120 | Post 1#", .Username = "Emi"})
For iThread = 0 To MyForum.Thread.Count - 1
For iPost = 0 To MyForum.Thread(iThread).Posts.Count - 1
Static Pst As New ForumPost
Pst = MyForum.Thread(iThread).Posts(iPost)
Console.WriteLine($"Content:{Pst.PostContent}, Username who post it:{Pst.Username}")
Next
Next
End Sub
End Class
Public Class Forum
Public Property Thread As New ThreadCollection
End Class
Public Class ForumThread
Inherits List(Of Integer)
Public Property Posts As New PostCollection
Sub New(id As Integer)
End Sub
End Class
Public Class ThreadCollection
Inherits List(Of ForumThread)
Public Overloads Sub Add(ByVal id As Integer)
MyBase.Add(New ForumThread(id))
End Sub
End Class
Public Class ForumPost
Public Property Username As String
Public Property PostContent As String
End Class
Public Class PostCollection
Inherits List(Of ForumPost)
End Class
' Content:Therad ID: 500 | Post: 1#, Username who post it:Don
' Content:Therad ID: 500 | Post: 2#, Username who post it:Shon
' Content:Therad ID: 500 | Post: 3#, Username who post it:Ron
' Content:Therad ID: 120 | Post 1#, Username who post it:Emi
그것의,하지만 내 질문의 작성하는 경우도? 또는 그것을 어떻게 든 향상시킬 수 있습니까?
감사합니다. 그게 내가 원하는거야. – Yoal223
이 답변으로 문제가 해결되면 수락하십시오. – jmcilhinney