SortedDictionary<TKey,TValue>.Values 屬性

定義

取得集合,包含 SortedDictionary<TKey,TValue> 中的值。

public:
 property System::Collections::Generic::SortedDictionary<TKey, TValue>::ValueCollection ^ Values { System::Collections::Generic::SortedDictionary<TKey, TValue>::ValueCollection ^ get(); };
public System.Collections.Generic.SortedDictionary<TKey,TValue>.ValueCollection Values { get; }
member this.Values : System.Collections.Generic.SortedDictionary<'Key, 'Value>.ValueCollection
Public ReadOnly Property Values As SortedDictionary(Of TKey, TValue).ValueCollection

屬性值

SortedDictionary<TKey,TValue>.ValueCollection,包含 SortedDictionary<TKey,TValue> 中的值。

範例

此程式代碼範例示範如何使用 屬性列舉字典 Values 中的值,以及如何列舉字典中的索引鍵和值。

此程式代碼範例是提供給 類別之較大範例的 SortedDictionary<TKey,TValue> 一部分。

// To get the values alone, use the Values property.
SortedDictionary<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);
}
' To get the values alone, use the Values property.
Dim valueColl _
    As SortedDictionary(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
// 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);
}
' 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

備註

中的SortedDictionary<TKey,TValue>.ValueCollection值會根據 Comparer 屬性排序,而且順序與 屬性所Keys傳回的相關聯索引鍵SortedDictionary<TKey,TValue>.KeyCollection順序相同。

SortedDictionary<TKey,TValue>.ValueCollection 回的 不是靜態複本, SortedDictionary<TKey,TValue>.ValueCollection 而是會參考原始 SortedDictionary<TKey,TValue>中的值。 因此,對的變更 SortedDictionary<TKey,TValue> 會繼續反映在 中 SortedDictionary<TKey,TValue>.ValueCollection

取得此屬性的值是 O (1) 作業。

適用於

另請參閱