在 VS 2010 中,我有一个很大的字符串列表,列表中的每个项目也包含字符串列表(它不会再进一步了)。好消息是只会添加。不会从列表中删除任何内容。
我不想使用数据库。由于列表可能会变得很大,所以 XML 对我来说似乎很慢。我找不到任何适用于我的案例的通用解决方案。任何想法?
编辑:好的,我猜我的一些代码会让它更清楚。
Class Word
Public theWord As String
Public SubWords As New List(Of SubWord)
Public Count As Integer = 1
Sub New(ByRef Word As String)
theWord = Word
End Sub
Public Sub AddSubWord(ByRef Word As String)
Dim SubWordCount As Integer = SubWords.Count - 1
Dim Found As Boolean
For i = 0 To SubWordCount
If SubWords(i).theWord = Word Then
SubWords(i).Count += 1
Found = True
Exit For
End If
Next
If Found = False Then
SubWords.Add(New SubWord(Word))
End If
End Sub
Public Overrides Function ToString() As String
Return theWord
End Function
End Class
Class SubWord
Public theWord As String
Public Count As Integer = 1
Sub New(ByRef Word As String)
theWord = Word
End Sub
Public Overrides Function ToString() As String
Return theWord
End Function
End Class
我的清单也是:
Dim Words As New List(Of Word)
目的是如果单词不在列表中,则将单词添加到列表中,如果不增加它的计数。子词也一样。稍后,所有列表将根据其计数进行排序。会有很多单词,每个单词都有一个巨大的子词列表。