SortedDictionary.Values Property

Gets a collection containing the values in the SortedDictionary.

Namespace: System.Collections.Generic
Assembly: System (in system.dll)

public ValueCollection Values { get; }
/** @property */
public ValueCollection get_Values ()

public function get Values () : ValueCollection

Not applicable.

Property Value

A SortedDictionary.ValueCollection containing the keys in the SortedDictionary.

The values in the SortedDictionary.ValueCollection are sorted according to the Comparer property, and are in the same order as the associated keys in the SortedDictionary.KeyCollection returned by the Keys property.

The returned SortedDictionary.ValueCollection is not a static copy; instead, the SortedDictionary.ValueCollection refers back to the values in the original SortedDictionary. Therefore, changes to the SortedDictionary continue to be reflected in the SortedDictionary.ValueCollection.

Getting the value of this property is an O(1) operation.

This code example shows how to enumerate the values in the dictionary using the Values property, and how to enumerate the keys and values in the dictionary.

This code example is part of a larger example provided for the SortedDictionary class.

    // To get the values alone, use the Values property.
    SortedDictionary<string, string>.ValueCollection valueColl = 

    // The elements of the ValueCollection are strongly typed
    // with the type that was specified for dictionary values.
    foreach( string s in valueColl )
        Console.WriteLine("Value = {0}", s);


    // When you use foreach to enumerate dictionary elements,
    // the elements are retrieved as KeyValuePair objects.
    foreach( KeyValuePair<string, string> kvp in openWith )
        Console.WriteLine("Key = {0}, Value = {1}", 
            kvp.Key, kvp.Value);

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0