C# SortedList GetKeyList

Description

SortedList GetKeyList gets the keys in a SortedList object.

Syntax

SortedList.GetKeyList has the following syntax.


public virtual IList GetKeyList()

Returns

SortedList.GetKeyList method returns An IList object containing the keys in the SortedList object.

Example


using System;/*from  ww w  .  j  a v  a 2  s . c  om*/
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);
    }
    Console.WriteLine("Getting the key list");
    IList myKeyList = mySortedList.GetKeyList();
    foreach(string myKey in myKeyList)
    {
      Console.WriteLine("myKey = " + myKey);
    }
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack