Dictionary<TKey,TValue>.Values 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會得到包含 中 Dictionary<TKey,TValue>值的集合。
public:
property System::Collections::Generic::Dictionary<TKey, TValue>::ValueCollection ^ Values { System::Collections::Generic::Dictionary<TKey, TValue>::ValueCollection ^ get(); };
public System.Collections.Generic.Dictionary<TKey,TValue>.ValueCollection Values { get; }
member this.Values : System.Collections.Generic.Dictionary<'Key, 'Value>.ValueCollection
Public ReadOnly Property Values As Dictionary(Of TKey, TValue).ValueCollection
屬性值
包含 中的 數值 Dictionary<TKey,TValue>ADictionary<TKey,TValue>.ValueCollection。
範例
此程式碼範例展示了如何使用 Values 屬性枚舉字典中的值,以及如何枚舉字典中的鍵與值。
此程式碼範例是該類別更大 Dictionary<TKey,TValue> 範例的一部分(openWith 此範例中使用的字典名稱)。
// 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);
}
// To get the values alone, use the Values property.
let valueColl = openWith.Values
// The elements of the ValueCollection are strongly typed
// with the type that was specified for dictionary values.
printfn ""
for s in valueColl do
printfn $"Value = {s}"
' 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
// 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.
printfn ""
for kvp in openWith do
printfn $"Key = {kvp.Key}, Value = {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
備註
中Dictionary<TKey,TValue>.ValueCollection值的順序未明確,但與屬性回傳Keys的Dictionary<TKey,TValue>.KeyCollection相關鍵順序相同。
回傳 Dictionary<TKey,TValue>.ValueCollection 的 不是靜態副本;而是 Dictionary<TKey,TValue>.ValueCollection 回溯到原始 Dictionary<TKey,TValue>中的值。 因此,變化 Dictionary<TKey,TValue> 會持續反映在 Dictionary<TKey,TValue>.ValueCollection中。
取得此性質的值需進行 O(1) 運算。