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 mySL1 As New SortedList(myHT)
Console.WriteLine("mySL1 (default):")
Try
mySL1.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL1)
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
|