C# SortedList ContainsKey

Description

SortedList ContainsKey determines whether a SortedList object contains a specific key.

Syntax

SortedList.ContainsKey has the following syntax.


public virtual bool ContainsKey(
  Object key
)

Parameters

SortedList.ContainsKey has the following parameters.

  • key - The key to locate in the SortedList object.

Returns

SortedList.ContainsKey method returns true if the SortedList object contains an element with the specified key; otherwise, false.

Example

The following code example shows how to determine whether a SortedList object contains a specific element.


using System;//w w  w  . j  ava  2  s  .c  o  m
using System.Collections;

public class SamplesSortedList  {

   public static void Main()  {
      SortedList mySL = new SortedList();
      mySL.Add( 2, "two" );
      mySL.Add( 4, "four" );
      mySL.Add( 1, "one" );
      mySL.Add( 3, "three" );
      mySL.Add( 0, "zero" );

      int myKey = 2;
      Console.WriteLine(mySL.ContainsKey( myKey ));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack