Export (0) Print
Expand All

Dictionary.Values Property

Gets a collection containing the values in the Dictionary.

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

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

public function get Values () : ValueCollection

Not applicable.

Property Value

A Dictionary.ValueCollection containing the values in the Dictionary.

The order of the values in the Dictionary.ValueCollection is unspecified, but it is the same order as the associated keys in the Dictionary.KeyCollection returned by the Keys property.

The returned Dictionary.ValueCollection is not a static copy; instead, the Dictionary.ValueCollection refers back to the values in the original Dictionary. Therefore, changes to the Dictionary continue to be reflected in the Dictionary.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 Dictionary class.

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

    // The elements of the ValueCollection are strongly typed
    // with the type that was specified for dictionary values.
    Console.WriteLine();
    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.
    Console.WriteLine();
    foreach( KeyValuePair<string, string> kvp in openWith )
    {
        Console.WriteLine("Key = {0}, Value = {1}", 
            kvp.Key, kvp.Value);
    }

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, 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

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft