This documentation is archived and is not being maintained.

Dictionary.Values Property

Gets a collection containing the values in the Dictionary.

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

Public ReadOnly Property Values As ValueCollection
Dim instance As Dictionary(Of TKey, TValue)
Dim value As ValueCollection

value = instance.Values

/** @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.
    Dim valueColl As _
        Dictionary(Of String, String).ValueCollection = _
    ' The elements of the ValueCollection are strongly typed
    ' with the type that was specified for dictionary values.
    For Each s As String In  valueColl
        Console.WriteLine("Value = {0}", s)
    Next s


    ' When you use foreach to enumerate dictionary elements,
    ' the elements are retrieved as KeyValuePair objects.
    For Each kvp As KeyValuePair(Of String, String) In openWith
        Console.WriteLine("Key = {0}, Value = {1}", _
            kvp.Key, kvp.Value)
    Next kvp

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