SortedDictionary<TKey,TValue> SortedDictionary<TKey,TValue> SortedDictionary<TKey,TValue> SortedDictionary<TKey,TValue> Class

定義

表示根據索引鍵,所排序的索引鍵/值組集合。Represents a collection of key/value pairs that are sorted on the key.

generic <typename TKey, typename TValue>
public ref class SortedDictionary : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IDictionary<TKey, TValue>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IReadOnlyCollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IReadOnlyDictionary<TKey, TValue>, System::Collections::IDictionary
[System.Serializable]
public class SortedDictionary<TKey,TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IDictionary<TKey,TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey,TValue>, System.Collections.IDictionary
type SortedDictionary<'Key, 'Value> = class
    interface IDictionary<'Key, 'Value>
    interface IDictionary
    interface IReadOnlyDictionary<'Key, 'Value>
    interface ICollection<KeyValuePair<'Key, 'Value>>
    interface seq<KeyValuePair<'Key, 'Value>>
    interface IEnumerable
    interface ICollection
    interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
Public Class SortedDictionary(Of TKey, TValue)
Implements ICollection(Of KeyValuePair(Of TKey, TValue)), IDictionary, IDictionary(Of TKey, TValue), IEnumerable(Of KeyValuePair(Of TKey, TValue)), IReadOnlyCollection(Of KeyValuePair(Of TKey, TValue)), IReadOnlyDictionary(Of TKey, TValue)

類型參數

TKey

字典中的索引鍵類型。The type of the keys in the dictionary.

TValue

字典中的值類型。The type of the values in the dictionary.

繼承
SortedDictionary<TKey,TValue>SortedDictionary<TKey,TValue>SortedDictionary<TKey,TValue>SortedDictionary<TKey,TValue>
屬性
實作

範例

下列程式碼範例會建立空SortedDictionary<TKey,TValue>之字串的字串索引鍵,並使用Add方法來加入一些項目。The following code example creates an empty SortedDictionary<TKey,TValue> of strings with string keys and uses the Add method to add some elements. 此範例示範Add方法會擲回ArgumentException時嘗試要加入重複的索引鍵。The example demonstrates that the Add method throws an ArgumentException when attempting to add a duplicate key.

此範例會使用Item[TKey]屬性 (C# 中為索引子) 來擷取值,示範KeyNotFoundException要求的索引鍵不存在,而且可以取代顯示索引鍵關聯的值時擲回。The example uses the Item[TKey] property (the indexer in C#) to retrieve values, demonstrating that a KeyNotFoundException is thrown when a requested key is not present, and showing that the value associated with a key can be replaced.

該示例顯示如何使用TryGetValue方法作為更有效的方式來檢索值,如果程序通常必須嘗試不在字典中的鍵值,並且它顯示如何使用ContainsKey方法來測試在調用 Add方法。The example shows how to use the TryGetValue method as a more efficient way to retrieve values if a program often must try key values that are not in the dictionary, and it shows how to use the ContainsKey method to test whether a key exists before calling the Add method.

此範例示範如何列舉的索引鍵和字典中的值以及如何列舉索引鍵,並單獨使用值Keys屬性和Values屬性。The example shows how to enumerate the keys and values in the dictionary and how to enumerate the keys and values alone using the Keys property and the Values property.

最後,此範例示範Remove方法。Finally, the example demonstrates the Remove method.

using System;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        // Create a new sorted dictionary of strings, with string
        // keys.
        SortedDictionary<string, string> openWith = 
            new SortedDictionary<string, string>();

        // Add some elements to the dictionary. There are no 
        // duplicate keys, but some of the values are duplicates.
        openWith.Add("txt", "notepad.exe");
        openWith.Add("bmp", "paint.exe");
        openWith.Add("dib", "paint.exe");
        openWith.Add("rtf", "wordpad.exe");

        // The Add method throws an exception if the new key is 
        // already in the dictionary.
        try
        {
            openWith.Add("txt", "winword.exe");
        }
        catch (ArgumentException)
        {
            Console.WriteLine("An element with Key = \"txt\" already exists.");
        }

        // The Item property is another name for the indexer, so you 
        // can omit its name when accessing elements. 
        Console.WriteLine("For key = \"rtf\", value = {0}.", 
            openWith["rtf"]);

        // The indexer can be used to change the value associated
        // with a key.
        openWith["rtf"] = "winword.exe";
        Console.WriteLine("For key = \"rtf\", value = {0}.", 
            openWith["rtf"]);

        // If a key does not exist, setting the indexer for that key
        // adds a new key/value pair.
        openWith["doc"] = "winword.exe";

        // The indexer throws an exception if the requested key is
        // not in the dictionary.
        try
        {
            Console.WriteLine("For key = \"tif\", value = {0}.", 
                openWith["tif"]);
        }
        catch (KeyNotFoundException)
        {
            Console.WriteLine("Key = \"tif\" is not found.");
        }

        // When a program often has to try keys that turn out not to
        // be in the dictionary, TryGetValue can be a more efficient 
        // way to retrieve values.
        string value = "";
        if (openWith.TryGetValue("tif", out value))
        {
            Console.WriteLine("For key = \"tif\", value = {0}.", value);
        }
        else
        {
            Console.WriteLine("Key = \"tif\" is not found.");
        }

        // ContainsKey can be used to test keys before inserting 
        // them.
        if (!openWith.ContainsKey("ht"))
        {
            openWith.Add("ht", "hypertrm.exe");
            Console.WriteLine("Value added for key = \"ht\": {0}", 
                openWith["ht"]);
        }

        // 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);
        }

        // 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 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);
        }

        // Use the Remove method to remove a key/value pair.
        Console.WriteLine("\nRemove(\"doc\")");
        openWith.Remove("doc");

        if (!openWith.ContainsKey("doc"))
        {
            Console.WriteLine("Key \"doc\" is not found.");
        }
    }
}

/* This code example produces the following output:

An element with Key = "txt" already exists.
For key = "rtf", value = wordpad.exe.
For key = "rtf", value = winword.exe.
Key = "tif" is not found.
Key = "tif" is not found.
Value added for key = "ht": hypertrm.exe

Key = bmp, Value = paint.exe
Key = dib, Value = paint.exe
Key = doc, Value = winword.exe
Key = ht, Value = hypertrm.exe
Key = rtf, Value = winword.exe
Key = txt, Value = notepad.exe

Value = paint.exe
Value = paint.exe
Value = winword.exe
Value = hypertrm.exe
Value = winword.exe
Value = notepad.exe

Key = bmp
Key = dib
Key = doc
Key = ht
Key = rtf
Key = txt

Remove("doc")
Key "doc" is not found.
 */
Imports System
Imports System.Collections.Generic

Public Class Example
    
    Public Shared Sub Main() 

        ' Create a new sorted dictionary of strings, with string 
        ' keys. 
        Dim openWith As New SortedDictionary(Of String, String)
        
        ' Add some elements to the dictionary. There are no 
        ' duplicate keys, but some of the values are duplicates.
        openWith.Add("txt", "notepad.exe")
        openWith.Add("bmp", "paint.exe")
        openWith.Add("dib", "paint.exe")
        openWith.Add("rtf", "wordpad.exe")
        
        ' The Add method throws an exception if the new key is 
        ' already in the dictionary.
        Try
            openWith.Add("txt", "winword.exe")
        Catch 
            Console.WriteLine("An element with Key = ""txt"" already exists.")
        End Try

        ' The Item property is the default property, so you 
        ' can omit its name when accessing elements. 
        Console.WriteLine("For key = ""rtf"", value = {0}.", _
            openWith("rtf"))
        
        ' The default Item property can be used to change the value
        ' associated with a key.
        openWith("rtf") = "winword.exe"
        Console.WriteLine("For key = ""rtf"", value = {0}.", _
            openWith("rtf"))
        
        ' If a key does not exist, setting the default Item property
        ' for that key adds a new key/value pair.
        openWith("doc") = "winword.exe"

        ' The default Item property throws an exception if the requested
        ' key is not in the dictionary.
        Try
            Console.WriteLine("For key = ""tif"", value = {0}.", _
                openWith("tif"))
        Catch 
            Console.WriteLine("Key = ""tif"" is not found.")
        End Try

        ' When a program often has to try keys that turn out not to
        ' be in the dictionary, TryGetValue can be a more efficient 
        ' way to retrieve values.
        Dim value As String = ""
        If openWith.TryGetValue("tif", value) Then
            Console.WriteLine("For key = ""tif"", value = {0}.", value)
        Else
            Console.WriteLine("Key = ""tif"" is not found.")
        End If

        ' ContainsKey can be used to test keys before inserting 
        ' them.
        If Not openWith.ContainsKey("ht") Then
            openWith.Add("ht", "hypertrm.exe")
            Console.WriteLine("Value added for key = ""ht"": {0}", _
                openWith("ht"))
        End If

        ' 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

        ' 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

        ' 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

        ' Use the Remove method to remove a key/value pair.
        Console.WriteLine(vbLf + "Remove(""doc"")")
        openWith.Remove("doc")
        
        If Not openWith.ContainsKey("doc") Then
            Console.WriteLine("Key ""doc"" is not found.")
        End If

    End Sub

End Class

' This code example produces the following output:
'
'An element with Key = "txt" already exists.
'For key = "rtf", value = wordpad.exe.
'For key = "rtf", value = winword.exe.
'Key = "tif" is not found.
'Key = "tif" is not found.
'Value added for key = "ht": hypertrm.exe
'
'Key = bmp, Value = paint.exe
'Key = dib, Value = paint.exe
'Key = doc, Value = winword.exe
'Key = ht, Value = hypertrm.exe
'Key = rtf, Value = winword.exe
'Key = txt, Value = notepad.exe
'
'Value = paint.exe
'Value = paint.exe
'Value = winword.exe
'Value = hypertrm.exe
'Value = winword.exe
'Value = notepad.exe
'
'Key = bmp
'Key = dib
'Key = doc
'Key = ht
'Key = rtf
'Key = txt
'
'Remove("doc")
'Key "doc" is not found.
' 

備註

SortedDictionary<TKey,TValue>泛型類別是 O (log n) 擷取使用二進位搜尋樹狀結構其中 n 是字典中的項目數。The SortedDictionary<TKey,TValue> generic class is a binary search tree with O(log n) retrieval, where n is the number of elements in the dictionary. 在這方面,就像是SortedList<TKey,TValue>泛型類別。In this respect, it is similar to the SortedList<TKey,TValue> generic class. 這兩個類別有類似的物件模型,並且兩者都具有 O (log n) 擷取。The two classes have similar object models, and both have O(log n) retrieval. 兩個類別不同之處是在記憶體使用量和速度的插入和移除:Where the two classes differ is in memory use and speed of insertion and removal:

每個索引鍵/值組可以擷取為KeyValuePair<TKey,TValue>結構,或是DictionaryEntry透過非泛型IDictionary介面。Each key/value pair can be retrieved as a KeyValuePair<TKey,TValue> structure, or as a DictionaryEntry through the nongeneric IDictionary interface.

索引鍵必須是不可變,只要當做索引鍵中使用SortedDictionary<TKey,TValue>Keys must be immutable as long as they are used as keys in the SortedDictionary<TKey,TValue>. 在每個索引鍵SortedDictionary<TKey,TValue>必須是唯一的。Every key in a SortedDictionary<TKey,TValue> must be unique. 金鑰不能null,值可以是,如果型別值但TValue是參考型別。A key cannot be null, but a value can be, if the value type TValue is a reference type.

SortedDictionary<TKey,TValue> 需要執行的索引鍵比較的比較子實作。SortedDictionary<TKey,TValue> requires a comparer implementation to perform key comparisons. 您可以指定實作IComparer<T>泛型介面使用的建構函式可接受comparer參數; 如果您未指定的實作中,預設 genericcomparerComparer<T>.Default用。You can specify an implementation of the IComparer<T> generic interface by using a constructor that accepts a comparer parameter; if you do not specify an implementation, the default genericcomparer Comparer<T>.Default is used. 如果型別TKey實作System.IComparable<T>泛型介面,預設比較子會使用該實作。If type TKey implements the System.IComparable<T> generic interface, the default comparer uses that implementation.

foreach陳述式的C#語言 (for each在C++, For Each Visual Basic 中) 傳回集合中的項目類型的物件。The foreach statement of the C# language (for each in C++, For Each in Visual Basic) returns an object of the type of the elements in the collection. 因為每個項目的SortedDictionary<TKey,TValue>是索引鍵/值組,項目型別不是索引鍵的類型或值的類型。Since each element of the SortedDictionary<TKey,TValue> is a key/value pair, the element type is not the type of the key or the type of the value. 相反地,項目型別是KeyValuePair<TKey,TValue>Instead, the element type is KeyValuePair<TKey,TValue>. 下列程式碼顯示C#, C++,和 Visual Basic 語法。The following code shows C#, C++, and Visual Basic syntax.

for each(KeyValuePair<String^, String^> kvp in myDictionary)
{
    Console::WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
foreach( KeyValuePair<string, string> kvp in myDictionary )
{
    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
For Each kvp As KeyValuePair(Of String, String) In myDictionary
    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value)
Next kvp

foreach陳述式是一個列舉值,以允許僅讀取集合,不寫入包裝函式。The foreach statement is a wrapper around the enumerator, which allows only reading from the collection, not writing to it.

建構函式

SortedDictionary<TKey,TValue>() SortedDictionary<TKey,TValue>() SortedDictionary<TKey,TValue>() SortedDictionary<TKey,TValue>()

初始化 SortedDictionary<TKey,TValue> 類別的新執行個體,其為空且為索引鍵型別使用預設的 IComparer<T> 實作。Initializes a new instance of the SortedDictionary<TKey,TValue> class that is empty and uses the default IComparer<T> implementation for the key type.

SortedDictionary<TKey,TValue>(IComparer<TKey>) SortedDictionary<TKey,TValue>(IComparer<TKey>) SortedDictionary<TKey,TValue>(IComparer<TKey>) SortedDictionary<TKey,TValue>(IComparer<TKey>)

初始化 SortedDictionary<TKey,TValue> 類別的新執行個體,其為空且使用指定的 IComparer<T> 實作來比較索引鍵。Initializes a new instance of the SortedDictionary<TKey,TValue> class that is empty and uses the specified IComparer<T> implementation to compare keys.

SortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>) SortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>) SortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>) SortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>)

初始化 SortedDictionary<TKey,TValue> 類別的新執行個體,其包含從指定的 IDictionary<TKey,TValue> 所複製的元素,並為索引鍵型別使用預設的 IComparer<T> 實作。Initializes a new instance of the SortedDictionary<TKey,TValue> class that contains elements copied from the specified IDictionary<TKey,TValue> and uses the default IComparer<T> implementation for the key type.

SortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>) SortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>) SortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>) SortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>)

初始化 SortedDictionary<TKey,TValue> 類別的新執行個體,其包含從指定的 IDictionary<TKey,TValue> 所複製的元素,並使用指定的 IComparer<T> 實作來比較索引鍵。Initializes a new instance of the SortedDictionary<TKey,TValue> class that contains elements copied from the specified IDictionary<TKey,TValue> and uses the specified IComparer<T> implementation to compare keys.

屬性

Comparer Comparer Comparer Comparer

取得 IComparer<T>,用於排序 SortedDictionary<TKey,TValue> 的項目。Gets the IComparer<T> used to order the elements of the SortedDictionary<TKey,TValue>.

Count Count Count Count

取得 SortedDictionary<TKey,TValue> 中所包含的索引鍵/值組數目。Gets the number of key/value pairs contained in the SortedDictionary<TKey,TValue>.

Item[TKey] Item[TKey] Item[TKey] Item[TKey]

取得或設定與指定之索引鍵相關聯的值。Gets or sets the value associated with the specified key.

Keys Keys Keys Keys

取得集合,包含 SortedDictionary<TKey,TValue> 中的索引鍵。Gets a collection containing the keys in the SortedDictionary<TKey,TValue>.

Values Values Values Values

取得集合,包含 SortedDictionary<TKey,TValue> 中的值。Gets a collection containing the values in the SortedDictionary<TKey,TValue>.

方法

Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue)

將有指定索引鍵和數值的項目加入 SortedDictionary<TKey,TValue>Adds an element with the specified key and value into the SortedDictionary<TKey,TValue>.

Clear() Clear() Clear() Clear()

移除 SortedDictionary<TKey,TValue> 中的所有項目。Removes all elements from the SortedDictionary<TKey,TValue>.

ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey)

判斷 SortedDictionary<TKey,TValue> 是否包含具有指定之索引鍵的項目。Determines whether the SortedDictionary<TKey,TValue> contains an element with the specified key.

ContainsValue(TValue) ContainsValue(TValue) ContainsValue(TValue) ContainsValue(TValue)

判斷 SortedDictionary<TKey,TValue> 是否包含具有指定值的項目。Determines whether the SortedDictionary<TKey,TValue> contains an element with the specified value.

CopyTo(KeyValuePair<TKey,TValue>[], Int32) CopyTo(KeyValuePair<TKey,TValue>[], Int32) CopyTo(KeyValuePair<TKey,TValue>[], Int32) CopyTo(KeyValuePair<TKey,TValue>[], Int32)

從指定索引處開始,複製 SortedDictionary<TKey,TValue> 的項目至 KeyValuePair<TKey,TValue> 結構的指定陣列。Copies the elements of the SortedDictionary<TKey,TValue> to the specified array of KeyValuePair<TKey,TValue> structures, starting at the specified index.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

傳回在 SortedDictionary<TKey,TValue> 中逐一查看的列舉值。Returns an enumerator that iterates through the SortedDictionary<TKey,TValue>.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(TKey) Remove(TKey) Remove(TKey) Remove(TKey)

SortedDictionary<TKey,TValue> 中移除具有指定之索引鍵的項目。Removes the element with the specified key from the SortedDictionary<TKey,TValue>.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
TryGetValue(TKey, TValue) TryGetValue(TKey, TValue) TryGetValue(TKey, TValue) TryGetValue(TKey, TValue)

取得與指定索引鍵關聯的值。Gets the value associated with the specified key.

明確介面實作

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

從指定的陣列索引處開始,將 ICollection<T> 的項目複製到陣列。Copies the elements of the ICollection<T> to an array, starting at the specified array index.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

取得值,這個值表示對 ICollection 的存取是否同步 (安全執行緒)。Gets a value indicating whether access to the ICollection is synchronized (thread safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

取得可用以同步存取 ICollection 的物件。Gets an object that can be used to synchronize access to the ICollection.

ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>)

將項目加入至 ICollection<T>Adds an item to the ICollection<T>.

ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>)

判斷 ICollection<T> 是否包含特定索引鍵和值。Determines whether the ICollection<T> contains a specific key and value.

ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly

取得值,指出 ICollection<T> 是否唯讀。Gets a value indicating whether the ICollection<T> is read-only.

ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>)

ICollection<T> 中移除第一次出現的指定項目。Removes the first occurrence of the specified element from the ICollection<T>.

IDictionary.Add(Object, Object) IDictionary.Add(Object, Object) IDictionary.Add(Object, Object) IDictionary.Add(Object, Object)

將具有提供索引鍵和值的元素加入至 IDictionaryAdds an element with the provided key and value to the IDictionary.

IDictionary.Contains(Object) IDictionary.Contains(Object) IDictionary.Contains(Object) IDictionary.Contains(Object)

判斷 IDictionary 是否包含具有指定之索引鍵的項目。Determines whether the IDictionary contains an element with the specified key.

IDictionary.GetEnumerator() IDictionary.GetEnumerator() IDictionary.GetEnumerator() IDictionary.GetEnumerator()

傳回 IDictionaryEnumeratorIDictionaryReturns an IDictionaryEnumerator for the IDictionary.

IDictionary.IsFixedSize IDictionary.IsFixedSize IDictionary.IsFixedSize IDictionary.IsFixedSize

取得值,指出 IDictionary 是否有固定的大小。Gets a value indicating whether the IDictionary has a fixed size.

IDictionary.IsReadOnly IDictionary.IsReadOnly IDictionary.IsReadOnly IDictionary.IsReadOnly

取得值,指出 IDictionary 是否唯讀。Gets a value indicating whether the IDictionary is read-only.

IDictionary.Item[Object] IDictionary.Item[Object] IDictionary.Item[Object] IDictionary.Item[Object]

取得或設定具有指定索引鍵的項目。Gets or sets the element with the specified key.

IDictionary.Keys IDictionary.Keys IDictionary.Keys IDictionary.Keys

取得 ICollection,包含 IDictionary 的索引鍵。Gets an ICollection containing the keys of the IDictionary.

IDictionary.Remove(Object) IDictionary.Remove(Object) IDictionary.Remove(Object) IDictionary.Remove(Object)

IDictionary 中移除具有指定之索引鍵的項目。Removes the element with the specified key from the IDictionary.

IDictionary.Values IDictionary.Values IDictionary.Values IDictionary.Values

取得 ICollection,包含 IDictionary 中的值。Gets an ICollection containing the values in the IDictionary.

IDictionary<TKey,TValue>.Keys IDictionary<TKey,TValue>.Keys IDictionary<TKey,TValue>.Keys IDictionary<TKey,TValue>.Keys

取得 ICollection<T>,包含 IDictionary<TKey,TValue> 的索引鍵。Gets an ICollection<T> containing the keys of the IDictionary<TKey,TValue>.

IDictionary<TKey,TValue>.Values IDictionary<TKey,TValue>.Values IDictionary<TKey,TValue>.Values IDictionary<TKey,TValue>.Values

取得 ICollection<T>,包含 IDictionary<TKey,TValue> 中的值。Gets an ICollection<T> containing the values in the IDictionary<TKey,TValue>.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

傳回逐一查看集合的列舉值。Returns an enumerator that iterates through the collection.

IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator() IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator() IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator() IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator()

傳回逐一查看集合的列舉值。Returns an enumerator that iterates through a collection.

IReadOnlyDictionary<TKey,TValue>.Keys IReadOnlyDictionary<TKey,TValue>.Keys IReadOnlyDictionary<TKey,TValue>.Keys IReadOnlyDictionary<TKey,TValue>.Keys

取得集合,包含 SortedDictionary<TKey,TValue> 中的索引鍵。Gets a collection containing the keys in the SortedDictionary<TKey,TValue>.

IReadOnlyDictionary<TKey,TValue>.Values IReadOnlyDictionary<TKey,TValue>.Values IReadOnlyDictionary<TKey,TValue>.Values IReadOnlyDictionary<TKey,TValue>.Values

取得集合,包含 SortedDictionary<TKey,TValue> 中的值。Gets a collection containing the values in the SortedDictionary<TKey,TValue>.

Extension Methods

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)
Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)
TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)
CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

傳回DataTable,其中包含副本DataRow物件,指定輸入IEnumerable<T>物件其中泛型參數TDataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

複本DataRow至指定的物件DataTable,根據輸入IEnumerable<T>物件其中泛型參數TDataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

複本DataRow至指定的物件DataTable,根據輸入IEnumerable<T>物件其中泛型參數TDataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

將轉換IEnumerableIQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

傳回包含來源集合中每個節點祖系的項目集合。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

傳回包含來源集合中每個節點祖系的已篩選項目集合。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目之子代節點的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

傳回包含來源集合中每個項目和文件之子代項目的項目集合。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

傳回已篩選的項目集合,其中包含來源集合中每個項目和文件的子代項目。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

傳回來源集合中每個項目和文件的子項目集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

傳回來源集合中每個項目和文件的已篩選子項目集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

傳回包含來源集合中所有節點的節點集合,依據文件順序來排序。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目的子節點集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

在來源集合中,從每一個節點的父節點移除這些節點。Removes every node in the source collection from its parent node.

適用於

執行緒安全性

公用靜態 (Shared Visual Basic 中) 的這種類型的成員都是安全執行緒。Public static (Shared in Visual Basic) members of this type are thread safe. 不保證任何執行個體成員是安全執行緒。Any instance members are not guaranteed to be thread safe.

ASortedDictionary<TKey,TValue>可支援多個讀取器同時,只要不修改集合。A SortedDictionary<TKey,TValue> can support multiple readers concurrently, as long as the collection is not modified. 即便如此,透過集合列舉是本質上並非安全執行緒程序。Even so, enumerating through a collection is intrinsically not a thread-safe procedure. 若要確保列舉期間的執行緒安全性,您可以在整個列舉期間鎖定集合。To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. 若要讓多重執行緒能夠存取集合以便進行讀取和寫入,您必須實作自己的同步處理。To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

另請參閱