共用方式為


SortedList<TKey,TValue> 類別

定義

表示索引鍵/值組的集合,這些索引鍵/值組會根據相關聯的 IComparer<T> 實作排序。

generic <typename TKey, typename TValue>
public ref class SortedList : 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
generic <typename TKey, typename TValue>
public ref class SortedList : 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::IDictionary
public class SortedList<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
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class SortedList<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.IDictionary
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class SortedList<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 SortedList<'Key, 'Value> = class
    interface ICollection<KeyValuePair<'Key, 'Value>>
    interface seq<KeyValuePair<'Key, 'Value>>
    interface IEnumerable
    interface IDictionary<'Key, 'Value>
    interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
    interface IReadOnlyDictionary<'Key, 'Value>
    interface ICollection
    interface IDictionary
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type SortedList<'Key, 'Value> = class
    interface IDictionary<'Key, 'Value>
    interface ICollection<KeyValuePair<'Key, 'Value>>
    interface seq<KeyValuePair<'Key, 'Value>>
    interface IDictionary
    interface ICollection
    interface IEnumerable
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type SortedList<'Key, 'Value> = class
    interface IDictionary<'Key, 'Value>
    interface ICollection<KeyValuePair<'Key, 'Value>>
    interface seq<KeyValuePair<'Key, 'Value>>
    interface IEnumerable
    interface IDictionary
    interface ICollection
    interface IReadOnlyDictionary<'Key, 'Value>
    interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
Public Class SortedList(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)
Public Class SortedList(Of TKey, TValue)
Implements ICollection(Of KeyValuePair(Of TKey, TValue)), IDictionary, IDictionary(Of TKey, TValue), IEnumerable(Of KeyValuePair(Of TKey, TValue))

類型參數

TKey

集合中的索引鍵類型。

TValue

集合中的值型別。

繼承
SortedList<TKey,TValue>
衍生
屬性
實作

範例

下列程式代碼範例會使用字串索引鍵建立空的字串 SortedList<TKey,TValue>,並使用 Add 方法來新增某些元素。 此範例示範嘗試新增重複索引鍵時,Add 方法會擲回 ArgumentException

此範例會使用 Item[] 屬性 (C# 中的索引器) 來擷取值,示範當要求索引鍵不存在時擲回 KeyNotFoundException,並顯示可以取代與索引鍵相關聯的值。

此範例示範如何使用 TryGetValue 方法作為擷取值更有效率的方式,如果程式通常必須嘗試不在排序列表中的索引鍵值,並示範如何使用 ContainsKey 方法來測試索引鍵是否存在,然後再呼叫 Add 方法。

此範例示範如何列舉已排序列表中的索引鍵和值,以及如何單獨使用 Keys 屬性和 Values 屬性列舉索引鍵和值。

最後,此範例示範 Remove 方法。

#using <System.dll>

using namespace System;
using namespace System::Collections::Generic;

public ref class Example
{
public:
    static void Main()
    {
        // Create a new sorted list of strings, with string
        // keys.
        SortedList<String^, String^>^ openWith =
            gcnew SortedList<String^, String^>();

        // Add some elements to the list. 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 list.
        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 list.
        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 list, TryGetValue can be a more efficient
        // way to retrieve values.
        String^ value = "";
        if (openWith->TryGetValue("tif", 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 list elements,
        // the elements are retrieved as KeyValuePair objects.
        Console::WriteLine();
        for each( 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.
        IList<String^>^ ilistValues = openWith->Values;

        // The elements of the list are strongly typed with the
        // type that was specified for the SortedList values.
        Console::WriteLine();
        for each( String^ s in ilistValues )
        {
            Console::WriteLine("Value = {0}", s);
        }

        // The Values property is an efficient way to retrieve
        // values by index.
        Console::WriteLine("\nIndexed retrieval using the Values " +
            "property: Values[2] = {0}", openWith->Values[2]);

        // To get the keys alone, use the Keys property.
        IList<String^>^ ilistKeys = openWith->Keys;

        // The elements of the list are strongly typed with the
        // type that was specified for the SortedList keys.
        Console::WriteLine();
        for each( String^ s in ilistKeys )
        {
            Console::WriteLine("Key = {0}", s);
        }

        // The Keys property is an efficient way to retrieve
        // keys by index.
        Console::WriteLine("\nIndexed retrieval using the Keys " +
            "property: Keys[2] = {0}", openWith->Keys[2]);

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

int main()
{
    Example::Main();
}

/* 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

Indexed retrieval using the Values property: Values[2] = winword.exe

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

Indexed retrieval using the Keys property: Keys[2] = doc

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

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

        // Add some elements to the list. 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 list.
        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 list.
        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 list, 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 list 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.
        IList<string> ilistValues = openWith.Values;

        // The elements of the list are strongly typed with the
        // type that was specified for the SortedList values.
        Console.WriteLine();
        foreach( string s in ilistValues )
        {
            Console.WriteLine("Value = {0}", s);
        }

        // The Values property is an efficient way to retrieve
        // values by index.
        Console.WriteLine("\nIndexed retrieval using the Values " +
            "property: Values[2] = {0}", openWith.Values[2]);

        // To get the keys alone, use the Keys property.
        IList<string> ilistKeys = openWith.Keys;

        // The elements of the list are strongly typed with the
        // type that was specified for the SortedList keys.
        Console.WriteLine();
        foreach( string s in ilistKeys )
        {
            Console.WriteLine("Key = {0}", s);
        }

        // The Keys property is an efficient way to retrieve
        // keys by index.
        Console.WriteLine("\nIndexed retrieval using the Keys " +
            "property: Keys[2] = {0}", openWith.Keys[2]);

        // 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

Indexed retrieval using the Values property: Values[2] = winword.exe

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

Indexed retrieval using the Keys property: Keys[2] = doc

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

Public Class Example
    
    Public Shared Sub Main() 

        ' Create a new sorted list of strings, with string 
        ' keys. 
        Dim openWith As New SortedList(Of String, String)
        
        ' Add some elements to the list. 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 list.
        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 list.
        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 list, 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 list 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 ilistValues As IList(Of String) = openWith.Values
        
        ' The elements of the list are strongly typed with the
        ' type that was specified for the SortedList values.
        Console.WriteLine()
        For Each s As String In ilistValues
            Console.WriteLine("Value = {0}", s)
        Next s

        ' The Values property is an efficient way to retrieve
        ' values by index.
        Console.WriteLine(vbLf & "Indexed retrieval using the " & _
            "Values property: Values(2) = {0}", openWith.Values(2))

        ' To get the keys alone, use the Keys property.
        Dim ilistKeys As IList(Of String) = openWith.Keys
        
        ' The elements of the list are strongly typed with the
        ' type that was specified for the SortedList keys.
        Console.WriteLine()
        For Each s As String In ilistKeys 
            Console.WriteLine("Key = {0}", s)
        Next s

        ' The Keys property is an efficient way to retrieve
        ' keys by index.
        Console.WriteLine(vbLf & "Indexed retrieval using the " & _
            "Keys property: Keys(2) = {0}", openWith.Keys(2))

        ' 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
'
'Indexed retrieval using the Values property: Values(2) = winword.exe
'
'Key = bmp
'Key = dib
'Key = doc
'Key = ht
'Key = rtf
'Key = txt
'
'Indexed retrieval using the Keys property: Keys(2) = doc
'
'Remove("doc")
'Key "doc" is not found.
'
open System
open System.Collections.Generic

// Create a new sorted list of strings, with string
// keys.
let openWith = SortedList<string, string>()

// Add some elements to the list. 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 list.
try
    openWith.Add("txt", "winword.exe");
with
    | :? ArgumentException ->
        printfn "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.
printfn $"""For key = "rtf", value = {openWith["rtf"]}."""

// The indexer can be used to change the value associated
// with a key.
openWith["rtf"] <- "winword.exe"
printfn $"""For key = "rtf", value = {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 list.
try
    printfn $"""For key = "tif", value = {openWith["tif"]}."""
with 
    | :? KeyNotFoundException ->
        printfn "Key = \"tif\" is not found."

// When a program often has to try keys that turn out not to
// be in the list, TryGetValue can be a more efficient
// way to retrieve values.
match openWith.TryGetValue("tif") with
| true, value ->
    printfn "For key = \"tif\", value = {value}."
| false, _ ->
    printfn "Key = \"tif\" is not found."

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

// When you use foreach to enumerate list elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine()
for kvp in openWith do
    printfn $"Key = {kvp.Key}, Value = {kvp.Value}"

// To get the values alone, use the Values property.
let ilistValues = openWith.Values;

// The elements of the list are strongly typed with the
// type that was specified for the SortedList values.
Console.WriteLine()
for s in ilistValues do
    printfn $"Value = {s}"

// The Values property is an efficient way to retrieve
// values by index.
printf "\nIndexed retrieval using the Values "
printfn $"property: Values[2] = {openWith.Values[2]}"

// To get the keys alone, use the Keys property.
let ilistKeys = openWith.Keys;

// The elements of the list are strongly typed with the
// type that was specified for the SortedList keys.
Console.WriteLine()
for s in ilistKeys do
    printfn $"Key = {s}"

// The Keys property is an efficient way to retrieve
// keys by index.
printf "\nIndexed retrieval using the Keys "
printfn $"property: Keys[2] = {openWith.Keys[2]}"

// Use the Remove method to remove a key/value pair.
printfn "\nRemove(\"doc\")"
openWith.Remove("doc") |> ignore

if not (openWith.ContainsKey("doc")) then
    printfn "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

Indexed retrieval using the Values property: Values[2] = winword.exe

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

Indexed retrieval using the Keys property: Keys[2] = doc

Remove("doc")
Key "doc" is not found.
 *)

備註

SortedList<TKey,TValue> 泛型類別是具有 O(log n) 擷取的索引鍵/值組陣列,其中 n 是字典中的元素數目。 在此中,它類似於 SortedDictionary<TKey,TValue> 泛型類別。 這兩個類別具有類似的物件模型,而且兩者都有 O(log n) 擷取。 兩個類別的差異在於記憶體使用和插入和移除的速度:

SortedDictionary<TKey,TValue>SortedList<TKey,TValue> 類別之間的另一個差異在於,SortedList<TKey,TValue> 透過 KeysValues 屬性所傳回的集合,支援有效率地擷取索引鍵和值。 存取屬性時不需要重新產生清單,因為清單只是索引鍵和值內部數位的包裝函式。 下列程式代碼示範如何使用 Values 屬性,從排序的字串清單中擷取值:

String^ v = mySortedList->Values[3];
string v = mySortedList.Values[3];
Dim v As String = mySortedList.Values(3)
let v = mySortedList.Values[3]

SortedList<TKey,TValue> 會實作為索引鍵/值組的陣列,依索引鍵排序。 每個專案都可以擷取為 KeyValuePair<TKey,TValue> 物件。

只要索引鍵物件在 SortedList<TKey,TValue>中當做索引鍵使用,就必須是固定的。 SortedList<TKey,TValue> 中的每個索引鍵都必須是唯一的。 索引鍵不能 null,但如果清單中的值類型 TValue為參考型別,則可以是值。

SortedList<TKey,TValue> 需要比較子實作來排序和執行比較。 默認比較子 Comparer<T>.Default 會檢查索引鍵類型 TKey 是否實作 System.IComparable<T>,並在可用時使用該實作。 如果沒有,Comparer<T>.Default 會檢查索引鍵類型 TKey 是否實作 System.IComparable。 如果索引鍵類型 TKey 未實作任一介面,您可以在接受 comparer 參數的建構函式多載中指定 System.Collections.Generic.IComparer<T> 實作。

SortedList<TKey,TValue> 的容量是 SortedList<TKey,TValue> 可以保存的項目數目。 當元素新增至 SortedList<TKey,TValue>時,重新配置內部數位會自動增加容量。 呼叫 TrimExcess 或明確設定 Capacity 屬性,即可減少容量。 減少容量會重新配置記憶體,並複製 SortedList<TKey,TValue>中的所有專案。

僅限 .NET Framework 對於非常大的 SortedList<TKey,TValue> 物件,您可以將運行時間環境中 <gcAllowVeryLargeObjects> 組態 true 專案的 enabled 屬性,將 64 位系統上的最大容量增加到 20 億個元素。

C# 語言的 foreach 語句 (for each 在 C++ 中,在 Visual Basic 中 For Each) 會傳回集合中專案類型的 物件。 由於 SortedList<TKey,TValue> 的專案是索引鍵/值組,因此項目類型不是索引鍵的類型或值的型別。 相反地,元素類型會 KeyValuePair<TKey,TValue>。 例如:

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

foreach 語句是列舉值周圍的包裝函式,它只允許讀取集合,而不是寫入集合。

建構函式

SortedList<TKey,TValue>()

初始化空 SortedList<TKey,TValue> 類別的新實體、具有預設的初始容量,並使用預設 IComparer<T>

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

初始化空 SortedList<TKey,TValue> 類別的新實例、具有預設的初始容量,並使用指定的 IComparer<T>

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

初始化 SortedList<TKey,TValue> 類別的新實例,這個實例包含從指定的 IDictionary<TKey,TValue>複製的專案,具有足夠的容量來容納複製的項目數目,並使用預設 IComparer<T>

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

初始化 SortedList<TKey,TValue> 類別的新實例,這個實例包含從指定的 IDictionary<TKey,TValue>複製的專案,具有足夠的容量來容納複製的項目數,並使用指定的 IComparer<T>

SortedList<TKey,TValue>(Int32)

初始化空 SortedList<TKey,TValue> 類別的新實體、具有指定的初始容量,並使用預設 IComparer<T>

SortedList<TKey,TValue>(Int32, IComparer<TKey>)

初始化空 SortedList<TKey,TValue> 類別的新實體、具有指定的初始容量,並使用指定的 IComparer<T>

屬性

Capacity

取得或設定 SortedList<TKey,TValue> 可以包含的項目數目。

Comparer

取得已排序列表的 IComparer<T>

Count

取得包含在 SortedList<TKey,TValue>中的索引鍵/值組數目。

Item[TKey]

取得或設定與指定索引鍵相關聯的值。

Keys

取得集合,其中包含以排序順序 SortedList<TKey,TValue>中的索引鍵。

Values

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

方法

Add(TKey, TValue)

將具有指定索引鍵和值的專案加入至 SortedList<TKey,TValue>

Clear()

SortedList<TKey,TValue>移除所有專案。

ContainsKey(TKey)

判斷 SortedList<TKey,TValue> 是否包含特定索引鍵。

ContainsValue(TValue)

判斷 SortedList<TKey,TValue> 是否包含特定值。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

傳回逐一查看 SortedList<TKey,TValue>的列舉值。

GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetKeyAtIndex(Int32)

取得對應至指定索引的索引鍵。

GetType()

取得目前實例的 Type

(繼承來源 Object)
GetValueAtIndex(Int32)

取得對應至指定索引的值。

IndexOfKey(TKey)

搜尋指定的索引鍵,並傳回整個 SortedList<TKey,TValue>內以零起始的索引。

IndexOfValue(TValue)

搜尋指定的值,並傳回整個 SortedList<TKey,TValue>內第一個出現專案的以零起始的索引。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
Remove(TKey)

SortedList<TKey,TValue>移除具有指定索引鍵的專案。

RemoveAt(Int32)

拿掉位於 SortedList<TKey,TValue>之指定索引處的專案。

SetValueAtIndex(Int32, TValue)

更新對應至指定索引的值。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)
TrimExcess()

如果這個數位小於目前容量的90%,請將容量設定為 SortedList<TKey,TValue>中的實際項目數目。

TryGetValue(TKey, TValue)

取得與指定索引鍵相關聯的值。

明確介面實作

ICollection.CopyTo(Array, Int32)

從特定 Array 索引開始,將 ICollection 的專案複製到 Array

ICollection.IsSynchronized

取得值,指出是否同步存取 ICollection (線程安全)。

ICollection.SyncRoot

取得對象,這個物件可用來同步存取 ICollection

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

將索引鍵/值組新增至 ICollection<T>

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

判斷 ICollection<T> 是否包含特定專案。

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

從特定 Array 索引開始,將 ICollection<T> 的專案複製到 Array

ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly

取得值,指出 ICollection<T> 是否為唯讀。

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

ICollection<T>移除第一個出現的特定索引鍵/值組。

IDictionary.Add(Object, Object)

將具有所提供索引鍵和值的專案加入至 IDictionary

IDictionary.Contains(Object)

判斷 IDictionary 是否包含具有指定索引鍵的專案。

IDictionary.GetEnumerator()

傳回 IDictionaryIDictionaryEnumerator

IDictionary.IsFixedSize

取得值,指出 IDictionary 是否有固定大小。

IDictionary.IsReadOnly

取得值,指出 IDictionary 是否為唯讀。

IDictionary.Item[Object]

取得或設定具有指定索引鍵的專案。

IDictionary.Keys

取得包含 IDictionary索引鍵的 ICollection

IDictionary.Remove(Object)

IDictionary移除具有指定索引鍵的專案。

IDictionary.Values

取得 ICollection,其中包含 IDictionary中的值。

IDictionary<TKey,TValue>.Keys

取得包含 IDictionary<TKey,TValue>索引鍵的 ICollection<T>

IDictionary<TKey,TValue>.Values

取得 ICollection<T>,其中包含 IDictionary<TKey,TValue>中的值。

IEnumerable.GetEnumerator()

傳回逐一查看集合的列舉值。

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

傳回逐一查看集合的列舉值。

IReadOnlyDictionary<TKey,TValue>.Keys

取得可列舉集合,其中包含唯讀字典中的索引鍵。

IReadOnlyDictionary<TKey,TValue>.Values

取得可列舉集合,其中包含唯讀字典中的值。

擴充方法

ToFrozenDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式,從 IEnumerable<T> 建立 FrozenDictionary<TKey,TValue>

ToFrozenDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器和項目選取器函式,從 IEnumerable<T> 建立 FrozenDictionary<TKey,TValue>

ToFrozenSet<T>(IEnumerable<T>, IEqualityComparer<T>)

使用指定的值建立 FrozenSet<T>

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

傳回目前字典的唯讀 ReadOnlyDictionary<TKey,TValue> 包裝函式。

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)

嘗試在 dictionary中取得與指定之 key 相關聯的值。

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)

嘗試在 dictionary中取得與指定之 key 相關聯的值。

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

嘗試從 dictionary移除具有指定 key 的值。

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

試著將指定的 keyvalue 新增至 dictionary

ToImmutableArray<TSource>(IEnumerable<TSource>)

從指定的集合建立不可變的陣列。

ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

從現有的專案集合建構不可變的字典,將轉換函式套用至來源索引鍵。

ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據序列的一些轉換,建構不可變的字典。

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>)

列舉和轉換序列,併產生其內容的不可變字典。

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>)

列舉和轉換序列,並使用指定的索引鍵比較子產生其內容的不可變字典。

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>, IEqualityComparer<TValue>)

列舉和轉換序列,並使用指定的索引鍵和值比較子產生其內容的不可變字典。

ToImmutableHashSet<TSource>(IEnumerable<TSource>)

列舉序列,併產生其內容的不可變哈希集。

ToImmutableHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>)

列舉序列、產生其內容的不可變哈希集,並使用集合類型的指定相等比較子。

ToImmutableList<TSource>(IEnumerable<TSource>)

列舉序列,併產生其內容的不可變清單。

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>)

列舉和轉換序列,併產生其內容的不可變排序字典。

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>)

列舉和轉換序列,並使用指定的索引鍵比較子產生其內容的不可變排序字典。

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>, IEqualityComparer<TValue>)

列舉和轉換序列,並使用指定的索引鍵和值比較子產生其內容的不可變排序字典。

ToImmutableSortedSet<TSource>(IEnumerable<TSource>)

列舉序列,併產生其內容的不可變排序集。

ToImmutableSortedSet<TSource>(IEnumerable<TSource>, IComparer<TSource>)

列舉序列、產生其內容的不可變排序集,並使用指定的比較子。

CopyToDataTable<T>(IEnumerable<T>)

傳回包含 DataRow 物件複本的 DataTable,指定泛型參數 TDataRow的輸入 IEnumerable<T> 物件。

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

DataRow 物件複製到指定的 DataTable,指定輸入 IEnumerable<T> 物件,其中泛型參數 TDataRow

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

DataRow 物件複製到指定的 DataTable,指定輸入 IEnumerable<T> 物件,其中泛型參數 TDataRow

Aggregate<TSource>(IEnumerable<TSource>, Func<TSource,TSource,TSource>)

在序列上套用累加器函式。

Aggregate<TSource,TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>)

在序列上套用累加器函式。 指定的種子值會當做初始累加器值使用。

Aggregate<TSource,TAccumulate,TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, Func<TAccumulate,TResult>)

在序列上套用累加器函式。 指定的種子值會當做初始累加器值使用,而指定的函式則用來選取結果值。

AggregateBy<TSource,TKey,TAccumulate>(IEnumerable<TSource>, Func<TSource, TKey>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, IEqualityComparer<TKey>)

表示索引鍵/值組的集合,這些索引鍵/值組會根據相關聯的 IComparer<T> 實作排序。

AggregateBy<TSource,TKey,TAccumulate>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TKey,TAccumulate>, Func<TAccumulate,TSource,TAccumulate>, IEqualityComparer<TKey>)

表示索引鍵/值組的集合,這些索引鍵/值組會根據相關聯的 IComparer<T> 實作排序。

All<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

判斷序列的所有專案是否符合條件。

Any<TSource>(IEnumerable<TSource>)

判斷序列是否包含任何專案。

Any<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

判斷序列的任何專案是否符合條件。

Append<TSource>(IEnumerable<TSource>, TSource)

將值附加至序列結尾。

AsEnumerable<TSource>(IEnumerable<TSource>)

傳回輸入類型為 IEnumerable<T>

Average<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)

計算 Decimal 值序列的平均值,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Double>)

計算 Double 值序列的平均值,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)

計算 Int32 值序列的平均值,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)

計算 Int64 值序列的平均值,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Decimal 值序列的平均值。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Double 值序列的平均值。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Int32 值序列的平均值。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Int64 值序列的平均值。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Single 值序列的平均值。

Average<TSource>(IEnumerable<TSource>, Func<TSource,Single>)

計算 Single 值序列的平均值,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

Chunk<TSource>(IEnumerable<TSource>, Int32)

將序列的專案分割成大社區塊,最多 size

Concat<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

串連兩個序列。

Contains<TSource>(IEnumerable<TSource>, TSource)

判斷序列是否使用預設相等比較子來包含指定的專案。

Contains<TSource>(IEnumerable<TSource>, TSource, IEqualityComparer<TSource>)

使用指定的 IEqualityComparer<T>,判斷序列是否包含指定的專案。

Count<TSource>(IEnumerable<TSource>)

傳回序列中的項目數目。

Count<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

傳回數位,代表指定序列中滿足條件的項目數目。

CountBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

表示索引鍵/值組的集合,這些索引鍵/值組會根據相關聯的 IComparer<T> 實作排序。

DefaultIfEmpty<TSource>(IEnumerable<TSource>)

如果序列是空的,則傳回指定序列的專案或單一集合中型別參數的預設值。

DefaultIfEmpty<TSource>(IEnumerable<TSource>, TSource)

如果序列是空的,則傳回指定序列的專案或單一集合中的指定值。

Distinct<TSource>(IEnumerable<TSource>)

使用預設相等比較子來比較值,從序列傳回不同的專案。

Distinct<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>)

使用指定的 IEqualityComparer<T> 來比較值,從序列傳回不同的專案。

DistinctBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,從序列傳回不同的專案。

DistinctBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式,並使用指定的比較子來比較索引鍵,從序列傳回不同的專案。

ElementAt<TSource>(IEnumerable<TSource>, Index)

傳回序列中指定索引處的專案。

ElementAt<TSource>(IEnumerable<TSource>, Int32)

傳回序列中指定索引處的專案。

ElementAtOrDefault<TSource>(IEnumerable<TSource>, Index)

傳回序列中指定索引處的專案,如果索引超出範圍,則傳回預設值。

ElementAtOrDefault<TSource>(IEnumerable<TSource>, Int32)

傳回序列中指定索引處的專案,如果索引超出範圍,則傳回預設值。

Except<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

使用預設相等比較子來比較值,產生兩個序列的集合差異。

Except<TSource>(IEnumerable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

使用指定的 IEqualityComparer<T> 來比較值,產生兩個序列的集合差異。

ExceptBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,產生兩個序列的集合差異。

ExceptBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式,產生兩個序列的集合差異。

First<TSource>(IEnumerable<TSource>)

傳回序列的第一個專案。

First<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

傳回序列中符合指定條件的第一個專案。

FirstOrDefault<TSource>(IEnumerable<TSource>)

傳回序列的第一個專案,如果序列不包含任何專案,則傳回預設值。

FirstOrDefault<TSource>(IEnumerable<TSource>, TSource)

傳回序列的第一個專案,如果序列不包含任何專案,則傳回指定的預設值。

FirstOrDefault<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

傳回序列的第一個專案,如果找不到這類專案,則為符合條件或預設值。

FirstOrDefault<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>, TSource)

傳回序列中符合條件的第一個專案,如果沒有找到這類專案,則傳回指定的預設值。

GroupBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,將序列的專案分組。

GroupBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式將序列的專案分組,並使用指定的比較子比較索引鍵。

GroupBy<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>)

根據指定的索引鍵選取器函式將序列的專案分組,並使用指定的函式來投影每個群組的專案。

GroupBy<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

根據索引鍵選取器函式,將序列的專案分組。 索引鍵是使用比較子來比較,而且每個群組的元素都是使用指定的函式來投影。

GroupBy<TSource,TKey,TResult>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TKey,IEnumerable<TSource>,TResult>)

根據指定的索引鍵選取器函式,將序列的專案分組,並從每個群組及其索引鍵建立結果值。

GroupBy<TSource,TKey,TResult>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TKey,IEnumerable<TSource>,TResult>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式,將序列的專案分組,並從每個群組及其索引鍵建立結果值。 使用指定的比較子來比較索引鍵。

GroupBy<TSource,TKey,TElement,TResult>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, Func<TKey,IEnumerable<TElement>,TResult>)

根據指定的索引鍵選取器函式,將序列的專案分組,並從每個群組及其索引鍵建立結果值。 每個群組的項目都會使用指定的函式來投影。

GroupBy<TSource,TKey,TElement,TResult>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource,TElement>, Func<TKey,IEnumerable<TElement>, TResult>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式,將序列的專案分組,並從每個群組及其索引鍵建立結果值。 索引鍵值是使用指定的比較子來比較,而每個群組的元素都是使用指定的函式來投影。

GroupJoin<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>, Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,IEnumerable<TInner>, TResult>)

根據索引鍵的相等性,將兩個序列的專案相互關聯,並將結果分組。 默認相等比較子可用來比較索引鍵。

GroupJoin<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>, Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,IEnumerable<TInner>, TResult>, IEqualityComparer<TKey>)

根據索引鍵相等將兩個序列的專案相互關聯,並將結果分組。 指定的 IEqualityComparer<T> 可用來比較索引鍵。

Index<TSource>(IEnumerable<TSource>)

傳回可列舉,將元素的索引併入 Tuple 中。

Intersect<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

使用預設相等比較子比較值來產生兩個序列的集合交集。

Intersect<TSource>(IEnumerable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

使用指定的 IEqualityComparer<T> 來比較值,產生兩個序列的集合交集。

IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,產生兩個序列的集合交集。

IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式,產生兩個序列的集合交集。

Join<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>, Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,TInner,TResult>)

根據比對索引鍵,將兩個序列的專案相互關聯。 默認相等比較子可用來比較索引鍵。

Join<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>, Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,TInner,TResult>, IEqualityComparer<TKey>)

根據比對索引鍵,將兩個序列的專案相互關聯。 指定的 IEqualityComparer<T> 可用來比較索引鍵。

Last<TSource>(IEnumerable<TSource>)

傳回序列的最後一個專案。

Last<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

傳回符合指定條件之序列的最後一個專案。

LastOrDefault<TSource>(IEnumerable<TSource>)

傳回序列的最後一個專案,如果序列不包含任何專案,則傳回預設值。

LastOrDefault<TSource>(IEnumerable<TSource>, TSource)

傳回序列的最後一個專案,如果序列不包含任何專案,則傳回指定的預設值。

LastOrDefault<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

傳回序列的最後一個專案,如果找不到這類專案,則為符合條件或預設值。

LastOrDefault<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>, TSource)

傳回符合條件之序列的最後一個專案,如果沒有找到這類專案,則傳回指定的預設值。

LongCount<TSource>(IEnumerable<TSource>)

傳回代表序列中項目總數的 Int64

LongCount<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

傳回 Int64,代表序列中滿足條件的項目數目。

Max<TSource>(IEnumerable<TSource>)

傳回泛型序列中的最大值。

Max<TSource>(IEnumerable<TSource>, IComparer<TSource>)

傳回泛型序列中的最大值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)

在序列的每個元素上叫用轉換函式,並傳回最大 Decimal 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Double>)

在序列的每個元素上叫用轉換函式,並傳回最大 Double 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)

在序列的每個元素上叫用轉換函式,並傳回最大 Int32 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)

在序列的每個元素上叫用轉換函式,並傳回最大 Int64 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)

在序列的每個元素上叫用轉換函式,並傳回可為 Null 的最大 Decimal 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)

在序列的每個元素上叫用轉換函式,並傳回可為 Null 的最大 Double 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)

在序列的每個元素上叫用轉換函式,並傳回可為 Null 的最大 Int32 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)

在序列的每個元素上叫用轉換函式,並傳回可為 Null 的最大 Int64 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)

在序列的每個元素上叫用轉換函式,並傳回可為 Null 的最大 Single 值。

Max<TSource>(IEnumerable<TSource>, Func<TSource,Single>)

在序列的每個元素上叫用轉換函式,並傳回最大 Single 值。

Max<TSource,TResult>(IEnumerable<TSource>, Func<TSource,TResult>)

在泛型序列的每個專案上叫用轉換函式,並傳回產生的最大值。

MaxBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,傳回泛型序列中的最大值。

MaxBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>)

根據指定的索引鍵選取器函式和索引鍵比較子,傳回泛型序列中的最大值。

Min<TSource>(IEnumerable<TSource>)

傳回泛型序列中的最小值。

Min<TSource>(IEnumerable<TSource>, IComparer<TSource>)

傳回泛型序列中的最小值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)

在序列的每個元素上叫用轉換函式,並傳回最小值 Decimal 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Double>)

在序列的每個元素上叫用轉換函式,並傳回最小值 Double 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)

在序列的每個元素上叫用轉換函式,並傳回最小值 Int32 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)

在序列的每個元素上叫用轉換函式,並傳回最小值 Int64 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)

在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 Decimal 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)

在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 Double 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)

在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 Int32 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)

在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 Int64 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)

在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 Single 值。

Min<TSource>(IEnumerable<TSource>, Func<TSource,Single>)

在序列的每個元素上叫用轉換函式,並傳回最小值 Single 值。

Min<TSource,TResult>(IEnumerable<TSource>, Func<TSource,TResult>)

在泛型序列的每個專案上叫用轉換函式,並傳回產生的最小值。

MinBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,傳回泛型序列中的最小值。

MinBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>)

根據指定的索引鍵選取器函式和索引鍵比較子,傳回泛型序列中的最小值。

OfType<TResult>(IEnumerable)

根據指定的型別篩選 IEnumerable 的專案。

Order<T>(IEnumerable<T>)

以遞增順序排序序列的專案。

Order<T>(IEnumerable<T>, IComparer<T>)

以遞增順序排序序列的專案。

OrderBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據索引鍵,以遞增順序排序序列的專案。

OrderBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>)

使用指定的比較子,以遞增順序排序序列的專案。

OrderByDescending<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據索引鍵,以遞減順序排序序列的專案。

OrderByDescending<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>)

使用指定的比較子,以遞減順序排序序列的專案。

OrderDescending<T>(IEnumerable<T>)

依遞減順序排序序列的專案。

OrderDescending<T>(IEnumerable<T>, IComparer<T>)

依遞減順序排序序列的專案。

Prepend<TSource>(IEnumerable<TSource>, TSource)

將值加入序列的開頭。

Reverse<TSource>(IEnumerable<TSource>)

反轉序列中項目的順序。

Select<TSource,TResult>(IEnumerable<TSource>, Func<TSource,TResult>)

將序列的每個專案投影成新的表單。

Select<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,TResult>)

藉由合併元素的索引,將序列的每個專案投影成新的表單。

SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TResult>>)

將序列的每個專案投影到 IEnumerable<T>,並將產生的序列扁平化成一個序列。

SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TResult>>)

將序列的每個專案投影至 IEnumerable<T>,並將產生的序列扁平化成一個序列。 每個來源專案的索引會以該專案的投影形式使用。

SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)

將序列的每個專案投影到 IEnumerable<T>,將產生的序列扁平化成一個序列,並在其中的每個元素上叫用結果選取器函式。

SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)

將序列的每個專案投影到 IEnumerable<T>,將產生的序列扁平化成一個序列,並在其中的每個元素上叫用結果選取器函式。 每個來源專案的索引會用於該專案的中繼投影形式。

SequenceEqual<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

判斷兩個序列是否相等,方法是使用其型別的默認相等比較子來比較專案。

SequenceEqual<TSource>(IEnumerable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

使用指定的 IEqualityComparer<T>,判斷兩個序列是否相等。

Single<TSource>(IEnumerable<TSource>)

傳回序列的唯一專案,如果序列中沒有一個專案,則會擲回例外狀況。

Single<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

傳回序列中唯一符合指定條件的專案,如果有多個這類專案存在,則會擲回例外狀況。

SingleOrDefault<TSource>(IEnumerable<TSource>)

傳回序列的唯一專案;如果序列是空的,則傳回預設值;如果序列中有多個項目,這個方法會擲回例外狀況。

SingleOrDefault<TSource>(IEnumerable<TSource>, TSource)

傳回序列的唯一專案,如果序列是空的,則傳回指定的預設值;如果序列中有多個項目,這個方法會擲回例外狀況。

SingleOrDefault<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

傳回序列中唯一符合指定條件的專案,如果沒有這類專案,則傳回預設值;如果一個以上的專案符合條件,這個方法會擲回例外狀況。

SingleOrDefault<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>, TSource)

傳回序列中唯一符合指定條件的專案,如果沒有這類專案,則傳回指定的預設值;如果一個以上的專案符合條件,這個方法會擲回例外狀況。

Skip<TSource>(IEnumerable<TSource>, Int32)

略過序列中指定數目的專案,然後傳回其餘專案。

SkipLast<TSource>(IEnumerable<TSource>, Int32)

傳回新的可列舉集合,其中包含 source 的專案,並省略來源集合的最後一個 count 專案。

SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

只要指定的條件為 true,就會略過序列中的項目,然後傳回其餘元素。

SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>)

只要指定的條件為 true,就會略過序列中的項目,然後傳回其餘元素。 元素的索引用於述詞函式的邏輯中。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)

計算 Decimal 值序列的總和,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>)

計算 Double 值序列的總和,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)

計算 Int32 值序列的總和,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)

計算 Int64 值序列的總和,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Decimal 值的序列總和。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Double 值的序列總和。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Int32 值的序列總和。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Int64 值的序列總和。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)

計算在輸入序列的每個元素上叫用轉換函式所取得之可為 Null Single 值的序列總和。

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>)

計算 Single 值序列的總和,這些值是在輸入序列的每個元素上叫用轉換函式所取得。

Take<TSource>(IEnumerable<TSource>, Int32)

從序列開頭傳回指定的連續項目數目。

Take<TSource>(IEnumerable<TSource>, Range)

傳回序列中連續專案的指定範圍。

TakeLast<TSource>(IEnumerable<TSource>, Int32)

傳回新的可列舉集合,其中包含來自 source的最後一個 count 專案。

TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

只要指定的條件為 true,就會從序列傳回專案。

TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>)

只要指定的條件為 true,就會從序列傳回專案。 元素的索引用於述詞函式的邏輯中。

ToArray<TSource>(IEnumerable<TSource>)

IEnumerable<T>建立陣列。

ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,從 IEnumerable<T> 建立 Dictionary<TKey,TValue>

ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式和索引鍵比較子,從 IEnumerable<T> 建立 Dictionary<TKey,TValue>

ToDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>)

根據指定的索引鍵選取器和項目選取器函式,從 IEnumerable<T> 建立 Dictionary<TKey,TValue>

ToDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式、比較子和元素選取器函式,從 IEnumerable<T> 建立 Dictionary<TKey,TValue>

ToHashSet<TSource>(IEnumerable<TSource>)

IEnumerable<T>建立 HashSet<T>

ToHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>)

使用 comparer 比較索引鍵,從 IEnumerable<T> 建立 HashSet<T>

ToList<TSource>(IEnumerable<TSource>)

IEnumerable<T>建立 List<T>

ToLookup<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,從 IEnumerable<T> 建立 Lookup<TKey,TElement>

ToLookup<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式和索引鍵比較子,從 IEnumerable<T> 建立 Lookup<TKey,TElement>

ToLookup<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>)

根據指定的索引鍵選取器和項目選取器函式,從 IEnumerable<T> 建立 Lookup<TKey,TElement>

ToLookup<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式、比較子和元素選取器函式,從 IEnumerable<T> 建立 Lookup<TKey,TElement>

TryGetNonEnumeratedCount<TSource>(IEnumerable<TSource>, Int32)

嘗試判斷序列中的項目數目,而不強制列舉。

Union<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

使用預設相等比較子產生兩個序列的集合聯集。

Union<TSource>(IEnumerable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

使用指定的 IEqualityComparer<T>產生兩個序列的集合聯集。

UnionBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,產生兩個序列的集合聯集。

UnionBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根據指定的索引鍵選取器函式,產生兩個序列的集合聯集。

Where<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

根據述詞篩選值序列。

Where<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>)

根據述詞篩選值序列。 每個元素的索引都會用於述詞函式的邏輯中。

Zip<TFirst,TSecond>(IEnumerable<TFirst>, IEnumerable<TSecond>)

產生具有來自兩個指定序列之元素的 Tuple 序列。

Zip<TFirst,TSecond,TThird>(IEnumerable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>)

產生具有來自三個指定序列之元素的 Tuple 序列。

Zip<TFirst,TSecond,TResult>(IEnumerable<TFirst>, IEnumerable<TSecond>, Func<TFirst,TSecond,TResult>)

將指定的函式套用至兩個序列的對應專案,產生結果序列。

AsParallel(IEnumerable)

啟用查詢的平行處理。

AsParallel<TSource>(IEnumerable<TSource>)

啟用查詢的平行處理。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

AsQueryable<TElement>(IEnumerable<TElement>)

將泛型 IEnumerable<T> 轉換成泛型 IQueryable<T>

Ancestors<T>(IEnumerable<T>)

傳回專案集合,其中包含來源集合中每個節點的上階。

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

傳回元素的篩選集合,其中包含來源集合中每個節點的上階。 集合中只會包含具有相符 XName 的專案。

DescendantNodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和專案之子代節點的集合。

Descendants<T>(IEnumerable<T>)

傳回專案集合,其中包含來源集合中每個元素和檔的子代專案。

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

傳回篩選的專案集合,其中包含來源集合中每個元素和檔的子代專案。 集合中只會包含具有相符 XName 的專案。

Elements<T>(IEnumerable<T>)

傳回來源集合中每個專案和檔的子專案集合。

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

傳回來源集合中每個專案和檔之子項目的篩選集合。 集合中只會包含具有相符 XName 的專案。

InDocumentOrder<T>(IEnumerable<T>)

傳回包含來源集合中所有節點的節點集合,依檔順序排序。

Nodes<T>(IEnumerable<T>)

傳回來源集合中每個檔和專案之子節點的集合。

Remove<T>(IEnumerable<T>)

從來源集合的父節點中移除每個節點。

適用於

執行緒安全性

此類型的公用靜態 (Shared) 成員是安全線程。 不保證任何實例成員都是安全線程。

只要集合未修改,SortedList<TKey,TValue> 就可以同時支援多個讀取器。 即便如此,透過集合列舉本質上不是安全線程的程式。 若要保證列舉期間的線程安全性,您可以在整個列舉期間鎖定集合。 若要允許多個線程存取集合以進行讀取和寫入,您必須實作自己的同步處理。

另請參閱