Create SortedList that contains elements from dictionary
Imports System
Imports System.Collections
Imports System.Globalization
Public Class SamplesSortedList
Public Shared Sub Main()
Dim myHT As New Hashtable()
myHT.Add("A", "Hello")
myHT.Add("B", "World")
myHT.Add("C", "!")
Dim mySL1 As New SortedList(myHT)
Try
mySL1.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL1)
End Sub
Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList)
Console.WriteLine(" -KEY- -VALUE-")
Dim i As Integer
For i = 0 To myList.Count - 1
Console.WriteLine(" {0,-6}: {1}", _
myList.GetKey(i), myList.GetByIndex(i))
Next i
Console.WriteLine()
End Sub
End Class
Related examples in the same category