Use the ContainsValue() method to check if mySortedList contains a value : SortedList « Data Structure « C# / CSharp Tutorial






using System;
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");
    }
  }
}
myKey = AL
myKey = CA
myKey = FL
myKey = NY
myKey = WY
myValue = Alabama
myValue = California
myValue = Florida
myValue = New York
myValue = Wyoming
mySortedList contains the value Florida








11.33.SortedList
11.33.1.Create a SortedList using the default comparer
11.33.2.Create a SortedList using the specified case-insensitive comparer
11.33.3.Create a SortedList using the specified CaseInsensitiveComparer, which is based on the Turkish culture (tr-TR)
11.33.4.Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value
11.33.5.Add value to SortedList and get contents by integer indexes
11.33.6.Add element to SortedList by using the indexer.
11.33.7.Show integer indexes of entries
11.33.8.Get value by key indexer
11.33.9.Use the ContainsValue() method to check if mySortedList contains a value
11.33.10.Use the Remove() method to remove a key from SortedList
11.33.11.Get the key at index 3 using the GetKey() method
11.33.12.Get the index of the element with a key using the IndexOfKey() method
11.33.13.Get the index of the element with a value using the IndexOfValue() method
11.33.14.Get the key list using the GetKeyList() method
11.33.15.Get the value list using the GetValueList() method