C# SortedList Values
Description
SortedList Values
gets the values in a SortedList object.
Syntax
SortedList.Values
has the following syntax.
public virtual ICollection Values { get; }
Example
The following code gets
the index of the element with a key using the IndexOfKey()
method.
using System;// w w w . ja v a 2 s . c o m
using System.Collections;
class MainClass
{
public static void Main()
{
SortedList mySortedList = new SortedList();
mySortedList.Add("NY", "New York");
mySortedList.Add("FL", "Florida");
mySortedList.Add("AL", "Alabama");
mySortedList.Add("WY", "Wyoming");
mySortedList.Add("CA", "California");
foreach (string myKey in mySortedList.Keys)
{
Console.WriteLine("myKey = " + myKey);
}
foreach(string myValue in mySortedList.Values)
{
Console.WriteLine("myValue = " + myValue);
}
int myIndex = mySortedList.IndexOfKey("NY");
Console.WriteLine("The index of NY is " + myIndex);
}
}
The code above generates the following result.