SortedList.Contains Method determines whether a SortedList object contains 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(2, "two")
mySL.Add(4, "four")
mySL.Add(1, "one")
mySL.Add(3, "three")
mySL.Add(0, "zero")
Dim myKey As Integer = 2
Dim msg As String
If mySL.ContainsKey(myKey) Then
msg = "in the SortedList"
Else
msg = "NOT in the SortedList"
End If
Console.WriteLine("The key ""{0}"" is {1}.", myKey, msg)
Dim myValue As String = "three"
If mySL.ContainsValue(myValue) Then
msg = "in the SortedList"
Else
msg = "NOT in the SortedList"
End If
Console.WriteLine("The value ""{0}"" is {1}.", myValue, msg)
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