SortedDictionary<TKey,TValue>.Keys 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會得到包含 鍵值的 SortedDictionary<TKey,TValue>集合。
public:
property System::Collections::Generic::SortedDictionary<TKey, TValue>::KeyCollection ^ Keys { System::Collections::Generic::SortedDictionary<TKey, TValue>::KeyCollection ^ get(); };
public System.Collections.Generic.SortedDictionary<TKey,TValue>.KeyCollection Keys { get; }
member this.Keys : System.Collections.Generic.SortedDictionary<'Key, 'Value>.KeyCollection
Public ReadOnly Property Keys As SortedDictionary(Of TKey, TValue).KeyCollection
屬性值
SortedDictionary<TKey,TValue>.KeyCollection A 包含 的鍵。SortedDictionary<TKey,TValue>
範例
以下程式碼範例說明如何利用 屬性 Keys 枚舉字典中的鍵,以及如何枚舉字典中的鍵與值。
這些程式碼是更大範例的一部分,可以編譯並執行。 參見 SortedDictionary<TKey,TValue>。
// To get the keys alone, use the Keys property.
SortedDictionary<string, string>.KeyCollection keyColl =
openWith.Keys;
// The elements of the KeyCollection are strongly typed
// with the type that was specified for dictionary keys.
Console.WriteLine();
foreach( string s in keyColl )
{
Console.WriteLine("Key = {0}", s);
}
' To get the keys alone, use the Keys property.
Dim keyColl _
As SortedDictionary(Of String, String).KeyCollection = _
openWith.Keys
' The elements of the KeyCollection are strongly typed
' with the type that was specified for dictionary keys.
Console.WriteLine()
For Each s As String In keyColl
Console.WriteLine("Key = {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>.KeyCollection鍵是依據屬性Comparer排序,且與屬性回傳SortedDictionary<TKey,TValue>.ValueCollection的Values相關值順序相同。
返回 SortedDictionary<TKey,TValue>.KeyCollection 的 不是靜態副本;而是 SortedDictionary<TKey,TValue>.KeyCollection 回溯到原始 SortedDictionary<TKey,TValue>的金鑰。 因此,變化 SortedDictionary<TKey,TValue> 會持續反映在 SortedDictionary<TKey,TValue>.KeyCollection中。
取得此性質的值需進行 O(1) 運算。