I want to create a sorted list whose values are themselves sorted
lists. I wrote the following simple test program but it does not
behave as I would expect.
What I wanted to do was have the doorConflictList be keyed on a door
ID and contain a sorted list called conFlictList. I wrote this
expecting the following
doorConflictList should end up with 3 items.
Item 1 would be a sorted list with 1 item
Item 2 would be a sorted list with 2 items
Item 3 would be a sorted list with 3 items.
I expected to see :
Door 0
Value 0
Door 1
Value 0
Value 1
Door 2
Value 0
Value 1
Value 2
but instead I see:
Door 0
Value 0
Value 1
Value 2
Door 1
Value 0
Value 1
Value 2
Door 2
Value 0
Value 1
Value 2
What am I doing wrong?
Here is the code :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim conFlictList As New SortedList
Dim doorConflictList As New SortedList
Dim i As Integer
Dim m As Integer
Dim door As Integer
Dim numberOfDoors As Integer = 3
For door = 0 To numberOfDoors - 1
conFlictList.Clear()
For i = 0 To door
conFlictList.Add("Key " & i.ToString, "Value " &
i.ToString)
Next
doorConflictList.Add("Door " & door.ToString, conFlictList)
Next
Dim strMessage As String = ""
If doorConflictList.Count > 0 Then
For i = 0 To doorConflictList.Count - 1
strMessage += doorConflictList.GetKey(i) & vbCrLf
Dim theConflicts As SortedList = _
CType(doorConflictList.GetByIndex(i), SortedList)
If theConflicts.Count > 0 Then
For m = 0 To theConflicts.Count - 1
strMessage += " " & theConflicts.GetByIndex(m) &
vbCrLf
Next
End If
Next
End If
MessageBox.Show(strMessage)
End Sub
TIA
John