Imports System
Imports System.Collections
Imports System.Globalization
Public Class SamplesSortedList
Public Shared Sub Main()
Dim myHT As New Hashtable()
myHT.Add("FIRST", "Hello")
myHT.Add("SECOND", "World")
myHT.Add("THIRD", "!")
Dim mySL2 As New SortedList(myHT, New CaseInsensitiveComparer())
Console.WriteLine("mySL2 (case-insensitive comparer):")
Try
mySL2.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL2)
End Sub 'Main
Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList)
Dim i As Integer
For i = 0 To myList.Count - 1
Console.WriteLine("{0,-6}: {1}", myList.GetKey(i), myList.GetByIndex(i))
Next i
End Sub
End Class
|