C# SortedList ContainsValue

Description

SortedList ContainsValue determines whether a SortedList object contains a specific value.

Syntax

SortedList.ContainsValue has the following syntax.


public virtual bool ContainsValue(
  Object value
)

Parameters

SortedList.ContainsValue has the following parameters.

  • value - The value to locate in the SortedList object. The value can be null.

Returns

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

Example

The following code uses the ContainsValue() method to check if mySortedList contains a value.


using System;/*from  w  w  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);
    }
    
    if (mySortedList.ContainsValue("Florida"))
    {
      Console.WriteLine("mySortedList contains the value Florida");
    }
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack