私は、ツリーのクラスを持っています。しかし、間違いがある可能性があるため、ポジションを変更する必要がある場合もあります(Order in OrderByを注文した後、これは以下のようになります)。 linqのような簡単な方法で、その文の位置を変更して、以下に示す方法でギャップを避けてください。私は私たちの例では0から始まる位置を変更したいソート特定のオブジェクトが
2
5
77
1001
:
0
1
2
3
方法:
Public Function GetSelectedSentencesOnSectionLevel(section As HtmlSection) As List(Of HtmlSentence)
Dim sentencesList As New List(Of HtmlSentence)
For Each exSection As HtmlSection In _htmlFactory.SectionsList
If exSection.Name = section.Name Then
Dim sentencesList As New List(Of HtmlSentence)
If Not IsNothing(exSection.SubSections) Then
For Each exSubsection As HtmlSubSection In exSection.SubSections
If Not IsNothing(exSubsection.SelectedSentences) Then
For Each exSentence As HtmlSentence In exSubsection.SelectedSentences
sentencesList.Add(exSentence)
Next
End If
Next
End If
End If
Next
'sort sentences by Posiions ascending
sentencesList = sentencesList.OrderBy(Function(x) x.Position).ToList()
Return sentencesList
End Function
EDIT:ヘルパーのためのより多くのコード:
グローバルクラス:
Public Class HtmlFactory
Property SectionsList As List(Of HtmlSection)
Sub New()
SectionsList = New List(Of HtmlSection)
End Sub
Sub New(pSectionsList As List(Of HtmlSection))
_SectionsList = pSectionsList
End Sub
Public Sub AddSection(section As HtmlSection)
SectionsList.Add(section)
End Sub
....
あなたが取り組んでいるコレクションは何ですか? –
@BozhidarStoinevあなたは何を意味しているのですか? – Dino
'' List(Of HtmlSentence) '...' 'ExSection'はどこから来たのでしょうか?文のサブセクションは何ですか? –