请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
 Values 属性
全部折叠/全部展开 全部折叠
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
Dictionary.Values 属性

注意:此属性在 .NET Framework 2.0 版中是新增的。

获取包含 Dictionary 中的值的集合。

命名空间:System.Collections.Generic
程序集:mscorlib(在 mscorlib.dll 中)

Visual Basic(声明)
Public ReadOnly Property Values As ValueCollection
Visual Basic(用法)
Dim instance As Dictionary(Of TKey, TValue)
Dim value As ValueCollection

value = instance.Values
C#
public ValueCollection Values { get; }
C++
public:
property ValueCollection^ Values {
    ValueCollection^ get ();
}
J#
/** @property */
public ValueCollection get_Values ()
JScript
public function get Values () : ValueCollection

属性值

包含 Dictionary 中的值的 Dictionary.ValueCollection

未指定 Dictionary.ValueCollection 中值的顺序,但是该顺序与由 Keys 属性返回的 Dictionary.KeyCollection 中的相关联键的顺序相同。

返回的 Dictionary.ValueCollection 不是静态副本;相反,Dictionary.ValueCollection 反向引用原始 Dictionary 中的值。因此,对 Dictionary 的更改将继续反映到 Dictionary.ValueCollection 中。

获取此属性的值的运算复杂度为 O(1)。

此代码示例演示如何使用 Values 属性枚举字典中的值,并演示如何枚举字典中的键和值。

此代码示例摘自一个为 Dictionary 类提供的更大的示例。

Visual Basic
        ' To get the values alone, use the Values property.
        Dim valueColl As _
            Dictionary(Of String, String).ValueCollection = _
            openWith.Values
        
        ' The elements of the ValueCollection are strongly typed
        ' with the type that was specified for dictionary values.
        Console.WriteLine()
        For Each s As String In  valueColl
            Console.WriteLine("Value = {0}", s)
        Next s
<br /><span space="preserve">...</span><br />        ' When you use foreach to enumerate dictionary elements,
        ' the elements are retrieved as KeyValuePair objects.
        Console.WriteLine()
        For Each kvp As KeyValuePair(Of String, String) In openWith
            Console.WriteLine("Key = {0}, Value = {1}", _
                kvp.Key, kvp.Value)
        Next kvp
C#
        // 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);
        }
<br /><span space="preserve">...</span><br />        // 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 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

.NET Framework

受以下版本支持:2.0

.NET Compact Framework

受以下版本支持:2.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2010 Microsoft Corporation 版权所有。 保留所有权利 | 商标 | 隐私权声明
Page view tracker