Searches for a specific key
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
Public Class SamplesSortedList
Public Shared Sub Main()
Dim mySL As New SortedList()
mySL.Add(1, "one")
mySL.Add(3, "three")
mySL.Add(2, "two")
mySL.Add(4, "four")
mySL.Add(0, "zero")
PrintIndexAndKeysAndValues(mySL)
Dim myKey As Integer = 2
Console.WriteLine("The key ""{0}"" is at index {1}.", myKey,mySL.IndexOfKey(myKey))
End Sub
Public Shared Sub PrintIndexAndKeysAndValues(myList As SortedList)
Dim i As Integer
For i = 0 To myList.Count - 1
Console.WriteLine("[{0}]:{1}{2}", i, myList.GetKey(i),myList.GetByIndex(i))
Next i
End Sub
End Class
Related examples in the same category