私は3つの投稿と1つのスレッドを持つフォーラムを持っていると仮定します。サブコレクション付きのコレクション
私はこの最終的な結果を取得したい:私は辞書
を使用したくない*
Dim MyFourm As new Fourm
MyFourm.Thread.Add(545)''for ex 545 mean Thread ID.
MyForum.Thread(0).Post(1).Username
スレッドは、整数の集合(=スレッドID)でなければなりません ポストはポストタイプ の集まりでなければなりませんこの場合、コードは「最初のスレッドを選択し、2番目の投稿とこの投稿を書くユーザーのユーザー名を取得する」のようなものです。
少しプレイした後、私はこのコードを記述します。その書き込み場合
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