BlockingCollection<T> 類別

定義

提供安全執行緒集合適用的封鎖和界限容量,這個集合會實作 IProducerConsumerCollection<T>

generic <typename T>
public ref class BlockingCollection : IDisposable, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::ICollection
generic <typename T>
public ref class BlockingCollection : IDisposable, System::Collections::Generic::IEnumerable<T>, System::Collections::ICollection
public class BlockingCollection<T> : IDisposable, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public class BlockingCollection<T> : IDisposable, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection
[System.Runtime.InteropServices.ComVisible(false)]
public class BlockingCollection<T> : IDisposable, System.Collections.Generic.IEnumerable<T>, System.Collections.ICollection
[System.Runtime.InteropServices.ComVisible(false)]
public class BlockingCollection<T> : IDisposable, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection
public class BlockingCollection<T> : IDisposable, System.Collections.Generic.IEnumerable<T>, System.Collections.ICollection
type BlockingCollection<'T> = class
    interface seq<'T>
    interface IEnumerable
    interface IReadOnlyCollection<'T>
    interface ICollection
    interface IDisposable
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
type BlockingCollection<'T> = class
    interface seq<'T>
    interface IEnumerable
    interface IReadOnlyCollection<'T>
    interface ICollection
    interface IDisposable
[<System.Runtime.InteropServices.ComVisible(false)>]
type BlockingCollection<'T> = class
    interface seq<'T>
    interface ICollection
    interface IEnumerable
    interface IDisposable
[<System.Runtime.InteropServices.ComVisible(false)>]
type BlockingCollection<'T> = class
    interface seq<'T>
    interface IEnumerable
    interface ICollection
    interface IDisposable
    interface IReadOnlyCollection<'T>
type BlockingCollection<'T> = class
    interface seq<'T>
    interface ICollection
    interface IEnumerable
    interface IDisposable
Public Class BlockingCollection(Of T)
Implements ICollection, IDisposable, IEnumerable(Of T), IReadOnlyCollection(Of T)
Public Class BlockingCollection(Of T)
Implements ICollection, IDisposable, IEnumerable(Of T)

類型參數

T

集合中項目的類型。

繼承
BlockingCollection<T>
屬性
實作

範例

下列範例示範如何同時從封鎖集合新增和擷取專案:

using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;

class BlockingCollectionDemo
{
    static async Task Main()
    {
        await AddTakeDemo.BC_AddTakeCompleteAdding();
        TryTakeDemo.BC_TryTake();
        FromToAnyDemo.BC_FromToAny();
        await ConsumingEnumerableDemo.BC_GetConsumingEnumerable();
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
}
class AddTakeDemo
{
    // Demonstrates:
    //      BlockingCollection<T>.Add()
    //      BlockingCollection<T>.Take()
    //      BlockingCollection<T>.CompleteAdding()
    public static async Task BC_AddTakeCompleteAdding()
    {
        using (BlockingCollection<int> bc = new BlockingCollection<int>())
        {
            // Spin up a Task to populate the BlockingCollection
            Task t1 = Task.Run(() =>
            {
                bc.Add(1);
                bc.Add(2);
                bc.Add(3);
                bc.CompleteAdding();
            });

            // Spin up a Task to consume the BlockingCollection
            Task t2 = Task.Run(() =>
            {
                try
                {
                    // Consume the BlockingCollection
                    while (true) Console.WriteLine(bc.Take());
                }
                catch (InvalidOperationException)
                {
                    // An InvalidOperationException means that Take() was called on a completed collection
                    Console.WriteLine("That's All!");
                }
            });

            await Task.WhenAll(t1, t2);
        }
    }
}

class TryTakeDemo
{
    // Demonstrates:
    //      BlockingCollection<T>.Add()
    //      BlockingCollection<T>.CompleteAdding()
    //      BlockingCollection<T>.TryTake()
    //      BlockingCollection<T>.IsCompleted
    public static void BC_TryTake()
    {
        // Construct and fill our BlockingCollection
        using (BlockingCollection<int> bc = new BlockingCollection<int>())
        {
            int NUMITEMS = 10000;
            for (int i = 0; i < NUMITEMS; i++) bc.Add(i);
            bc.CompleteAdding();
            int outerSum = 0;

            // Delegate for consuming the BlockingCollection and adding up all items
            Action action = () =>
            {
                int localItem;
                int localSum = 0;

                while (bc.TryTake(out localItem)) localSum += localItem;
                Interlocked.Add(ref outerSum, localSum);
            };

            // Launch three parallel actions to consume the BlockingCollection
            Parallel.Invoke(action, action, action);

            Console.WriteLine("Sum[0..{0}) = {1}, should be {2}", NUMITEMS, outerSum, ((NUMITEMS * (NUMITEMS - 1)) / 2));
            Console.WriteLine("bc.IsCompleted = {0} (should be true)", bc.IsCompleted);
        }
    }
}

class FromToAnyDemo
{
    // Demonstrates:
    //      Bounded BlockingCollection<T>
    //      BlockingCollection<T>.TryAddToAny()
    //      BlockingCollection<T>.TryTakeFromAny()
    public static void BC_FromToAny()
    {
        BlockingCollection<int>[] bcs = new BlockingCollection<int>[2];
        bcs[0] = new BlockingCollection<int>(5); // collection bounded to 5 items
        bcs[1] = new BlockingCollection<int>(5); // collection bounded to 5 items

        // Should be able to add 10 items w/o blocking
        int numFailures = 0;
        for (int i = 0; i < 10; i++)
        {
            if (BlockingCollection<int>.TryAddToAny(bcs, i) == -1) numFailures++;
        }
        Console.WriteLine("TryAddToAny: {0} failures (should be 0)", numFailures);

        // Should be able to retrieve 10 items
        int numItems = 0;
        int item;
        while (BlockingCollection<int>.TryTakeFromAny(bcs, out item) != -1) numItems++;
        Console.WriteLine("TryTakeFromAny: retrieved {0} items (should be 10)", numItems);
    }
}

class ConsumingEnumerableDemo
{
    // Demonstrates:
    //      BlockingCollection<T>.Add()
    //      BlockingCollection<T>.CompleteAdding()
    //      BlockingCollection<T>.GetConsumingEnumerable()
    public static async Task BC_GetConsumingEnumerable()
    {
        using (BlockingCollection<int> bc = new BlockingCollection<int>())
        {
            // Kick off a producer task
            var producerTask = Task.Run(async () =>
            {
                for (int i = 0; i < 10; i++)
                {
                    bc.Add(i);
                    Console.WriteLine($"Producing: {i}");

                    await Task.Delay(100); // sleep 100 ms between adds
                }

                // Need to do this to keep foreach below from hanging
                bc.CompleteAdding();
            });

            // Now consume the blocking collection with foreach.
            // Use bc.GetConsumingEnumerable() instead of just bc because the
            // former will block waiting for completion and the latter will
            // simply take a snapshot of the current state of the underlying collection.
            foreach (var item in bc.GetConsumingEnumerable())
            {
                Console.WriteLine($"Consuming: {item}");
            }
            await producerTask; // Allow task to complete cleanup
        }
    }
}
open System
open System.Collections.Concurrent
open System.Threading
open System.Threading.Tasks

module AddTakeDemo =
    // Demonstrates:
    //      BlockingCollection<T>.Add()
    //      BlockingCollection<T>.Take()
    //      BlockingCollection<T>.CompleteAdding()
    let blockingCollectionAddTakeCompleteAdding () =
        task {
            use bc = new BlockingCollection<int>()
            // Spin up a Task to populate the BlockingCollection
            let t1 = 
                task {
                    bc.Add 1
                    bc.Add 2
                    bc.Add 3
                    bc.CompleteAdding()
                }

            // Spin up a Task to consume the BlockingCollection
            let t2 = 
                task {
                    try
                        // Consume consume the BlockingCollection
                        while true do 
                            printfn $"{bc.Take()}"
                    with :? InvalidOperationException ->
                        // An InvalidOperationException means that Take() was called on a completed collection
                        printfn "That's All!"
                }
            let! _ = Task.WhenAll(t1, t2)
            ()
        }

module TryTakeDemo =
    // Demonstrates:
    //      BlockingCollection<T>.Add()
    //      BlockingCollection<T>.CompleteAdding()
    //      BlockingCollection<T>.TryTake()
    //      BlockingCollection<T>.IsCompleted
    let blockingCollectionTryTake () =
        // Construct and fill our BlockingCollection
        use bc = new BlockingCollection<int>()
        let NUMITEMS = 10000;
        for i = 0 to NUMITEMS - 1 do
            bc.Add i
        bc.CompleteAdding()
        let mutable outerSum = 0

        // Delegate for consuming the BlockingCollection and adding up all items
        let action = 
            Action(fun () ->
                let mutable localItem = 0
                let mutable localSum = 0

                while bc.TryTake &localItem do
                    localSum <- localSum + localItem
                Interlocked.Add(&outerSum, localSum)
                |> ignore)

        // Launch three parallel actions to consume the BlockingCollection
        Parallel.Invoke(action, action, action)

        printfn $"Sum[0..{NUMITEMS}) = {outerSum}, should be {((NUMITEMS * (NUMITEMS - 1)) / 2)}"
        printfn $"bc.IsCompleted = {bc.IsCompleted} (should be true)"

module FromToAnyDemo =
    // Demonstrates:
    //      Bounded BlockingCollection<T>
    //      BlockingCollection<T>.TryAddToAny()
    //      BlockingCollection<T>.TryTakeFromAny()
    let blockingCollectionFromToAny () =
        let bcs = 
            [|
                new BlockingCollection<int>(5) // collection bounded to 5 items
                new BlockingCollection<int>(5) // collection bounded to 5 items
             |]
        // Should be able to add 10 items w/o blocking
        let mutable numFailures = 0;
        for i = 0 to 9 do
            if BlockingCollection<int>.TryAddToAny(bcs, i) = -1 then
                numFailures <- numFailures + 1
        printfn $"TryAddToAny: {numFailures} failures (should be 0)"

        // Should be able to retrieve 10 items
        let mutable numItems = 0
        let mutable item = 0
        while BlockingCollection<int>.TryTakeFromAny(bcs, &item) <> -1 do
            numItems <- numItems + 1
        printfn $"TryTakeFromAny: retrieved {numItems} items (should be 10)"

module ConsumingEnumerableDemo =
    // Demonstrates:
    //      BlockingCollection<T>.Add()
    //      BlockingCollection<T>.CompleteAdding()
    //      BlockingCollection<T>.GetConsumingEnumerable()
    let blockingCollectionGetConsumingEnumerable () =
        task {
            use bc = new BlockingCollection<int>()
            // Kick off a producer task
            let producerTask =
                task {
                    for i = 0 to 9 do
                        bc.Add i
                        printfn $"Producing: {i}"

                        do! Task.Delay 100 // sleep 100 ms between adds
                    // Need to do this to keep foreach below from hanging
                    bc.CompleteAdding()
                }

            // Now consume the blocking collection with foreach.
            // Use bc.GetConsumingEnumerable() instead of just bc because the
            // former will block waiting for completion and the latter will
            // simply take a snapshot of the current state of the underlying collection.
            for item in bc.GetConsumingEnumerable() do
                printfn $"Consuming: {item}"
            do! producerTask // Allow task to complete cleanup
        }

let main =
    task {
        do! AddTakeDemo.blockingCollectionAddTakeCompleteAdding ()
        TryTakeDemo.blockingCollectionTryTake ()
        FromToAnyDemo.blockingCollectionFromToAny ()
        do! ConsumingEnumerableDemo.blockingCollectionGetConsumingEnumerable ()
        printfn "Press any key to exit."
        Console.ReadKey(true) |> ignore
    }
main.Wait()
Imports System.Threading.Tasks
Imports System.Collections.Concurrent
Imports System.Threading

Class BlockingCollectionDemo
    Shared Sub Main()
        AddTakeDemo.BC_AddTakeCompleteAdding()
        TryTakeDemo.BC_TryTake()
        ToAnyDemo.BC_ToAny()
        ConsumingEnumerableDemo.BC_GetConsumingEnumerable()
        ' Keep the console window open in debug mode
        Console.WriteLine("Press any key to exit.")
        Console.ReadKey()
    End Sub
End Class

Class AddTakeDemo

    ' Demonstrates:
    ' BlockingCollection<T>.Add()
    ' BlockingCollection<T>.Take()
    ' BlockingCollection<T>.CompleteAdding()
    Shared Sub BC_AddTakeCompleteAdding()
        Using bc As New BlockingCollection(Of Integer)()

            ' Spin up a Task to populate the BlockingCollection 
            Using t1 As Task = Task.Factory.StartNew(
                Sub()
                    bc.Add(1)
                    bc.Add(2)
                    bc.Add(3)
                    bc.CompleteAdding()
                End Sub)
                ' Spin up a Task to consume the BlockingCollection
                Using t2 As Task = Task.Factory.StartNew(
                Sub()
                    Try
                        ' Consume the BlockingCollection
                        While True
                            Console.WriteLine(bc.Take())
                        End While
                    Catch generatedExceptionName As InvalidOperationException
                        ' An InvalidOperationException means that Take() was called on a completed collection
                        Console.WriteLine("That's All!")
                    End Try
                End Sub)

                    Task.WaitAll(t1, t2)
                End Using
            End Using
        End Using
    End Sub



End Class

'Imports System.Collections.Concurrent
'Imports System.Threading
'Imports System.Threading.Tasks

Class TryTakeDemo
    ' Demonstrates:
    ' BlockingCollection<T>.Add()
    ' BlockingCollection<T>.CompleteAdding()
    ' BlockingCollection<T>.TryTake()
    ' BlockingCollection<T>.IsCompleted
    Shared Sub BC_TryTake()
        ' Construct and fill our BlockingCollection
        Using bc As New BlockingCollection(Of Integer)()
            Dim NUMITEMS As Integer = 10000
            For i As Integer = 0 To NUMITEMS - 1
                bc.Add(i)
            Next
            bc.CompleteAdding()
            Dim outerSum As Integer = 0

            ' Delegate for consuming the BlockingCollection and adding up all items
            Dim action As Action =
                Sub()
                    Dim localItem As Integer
                    Dim localSum As Integer = 0

                    While bc.TryTake(localItem)
                        localSum += localItem
                    End While
                    Interlocked.Add(outerSum, localSum)
                End Sub

            ' Launch three parallel actions to consume the BlockingCollection
            Parallel.Invoke(action, action, action)

            Console.WriteLine("Sum[0..{0}) = {1}, should be {2}", NUMITEMS, outerSum, ((NUMITEMS * (NUMITEMS - 1)) / 2))
            Console.WriteLine("bc.IsCompleted = {0} (should be true)", bc.IsCompleted)
        End Using
    End Sub

End Class

'Imports System.Threading.Tasks
'Imports System.Collections.Concurrent

' Demonstrates:
' Bounded BlockingCollection<T>
' BlockingCollection<T>.TryAddToAny()
' BlockingCollection<T>.TryTakeFromAny()
Class ToAnyDemo
    Shared Sub BC_ToAny()
        Dim bcs As BlockingCollection(Of Integer)() = New BlockingCollection(Of Integer)(1) {}
        bcs(0) = New BlockingCollection(Of Integer)(5)
        ' collection bounded to 5 items
        bcs(1) = New BlockingCollection(Of Integer)(5)
        ' collection bounded to 5 items
        ' Should be able to add 10 items w/o blocking
        Dim numFailures As Integer = 0
        For i As Integer = 0 To 9
            If BlockingCollection(Of Integer).TryAddToAny(bcs, i) = -1 Then
                numFailures += 1
            End If
        Next
        Console.WriteLine("TryAddToAny: {0} failures (should be 0)", numFailures)

        ' Should be able to retrieve 10 items
        Dim numItems As Integer = 0
        Dim item As Integer
        While BlockingCollection(Of Integer).TryTakeFromAny(bcs, item) <> -1
            numItems += 1
        End While
        Console.WriteLine("TryTakeFromAny: retrieved {0} items (should be 10)", numItems)
    End Sub
End Class

'Imports System.Threading.Tasks
'Imports System.Collections.Concurrent

' Demonstrates:
' BlockingCollection<T>.Add()
' BlockingCollection<T>.CompleteAdding()
' BlockingCollection<T>.GetConsumingEnumerable()

Class ConsumingEnumerableDemo
    Shared Sub BC_GetConsumingEnumerable()
        Using bc As New BlockingCollection(Of Integer)()

            ' Kick off a producer task
            Task.Factory.StartNew(
                Sub()
                    For i As Integer = 0 To 9
                        bc.Add(i)
                        ' sleep 100 ms between adds
                        Thread.Sleep(100)
                    Next

                    ' Need to do this to keep foreach below from not responding.
                    bc.CompleteAdding()
                End Sub)
            ' Now consume the blocking collection with foreach.
            ' Use bc.GetConsumingEnumerable() instead of just bc because the
            ' former will block waiting for completion and the latter will
            ' simply take a snapshot of the current state of the underlying collection.
            For Each item In bc.GetConsumingEnumerable()
                Console.WriteLine(item)
            Next
        End Using
    End Sub
End Class

備註

BlockingCollection<T> 是提供下列專案的安全線程集合類別:

重要

此型別代表 IDisposable 介面。 當您完成使用型別時,您應該直接或間接處置它。 若要直接處置型別,請呼叫其 try/catch 區塊中的 Dispose 方法。 若要間接處置它,請使用語言建構函式,例如 using (在 C# 中) 或 Using (在 Visual Basic 中)。 如需詳細資訊,請參閱 IDisposable 介面文章中的<使用實作 IDisposable 的物件>一節。 此外,請注意,方法 Dispose() 不是安全線程。 的所有其他公用和受保護成員 BlockingCollection<T> 都是安全線程,而且可以從多個執行緒同時使用。

IProducerConsumerCollection<T> 表示允許安全線程加入和移除資料的集合。 BlockingCollection<T> 會當做 實例的 IProducerConsumerCollection<T> 包裝函式使用,並允許移除集合中的嘗試封鎖,直到資料可供移除為止。 同樣地,您可以建立 來 BlockingCollection<T> 強制執行 中 IProducerConsumerCollection<T> 允許之資料元素數目的上限;新增至集合的嘗試可能會封鎖,直到空間可供儲存新增的專案為止。 如此一來, BlockingCollection<T> 類似于傳統的封鎖佇列資料結構,不同之處在于基礎資料儲存機制會抽象化為 IProducerConsumerCollection<T>

BlockingCollection<T> 支援界限和封鎖。 周框表示您可以設定集合的最大容量。 在某些情況下,系結很重要,因為它可讓您控制記憶體中集合的大小上限,並防止產生執行緒在取用執行緒之前移動太遠。多個執行緒或工作可以同時將專案新增至集合,如果集合達到其指定的最大容量,則產生執行緒會封鎖,直到移除專案為止。 多位消費者可以同時移除項目,如果集合變成空的,則會在生產者新增項目之前封鎖使用執行緒。 產生執行緒可以呼叫 CompleteAdding 方法,以指出不會再新增任何專案。 消費者會監視 IsCompleted 屬性,以得知集合何時變成空的,以及何時無法再新增項目。

AddTake 作業通常會在迴圈中執行。 您可以藉由將 CancellationToken 物件傳入 或 TryTake 方法,然後在每次反復專案上檢查權杖 IsCancellationRequested 屬性的值, TryAdd 以取消迴圈。 如果值為 true ,則您可以清除任何資源並結束迴圈,以回應取消要求。

當您建立 BlockingCollection<T> 物件時,不僅可以指定限定的容量,也可以指定要使用的集合類型。 例如,您可以針對先進先出 (FIFO) 行為指定 ConcurrentQueue<T> 物件,或針對後進先出 (LIFO) 行為指定 ConcurrentStack<T> 物件。 您可以使用任何可實作 IProducerConsumerCollection<T> 介面的集合類別。 BlockingCollection<T> 的預設集合類型為 ConcurrentQueue<T>

請勿直接修改基礎集合。 使用 BlockingCollection<T> 方法來加入或移除專案。 如果您直接變更基礎集合,物件 BlockingCollection<T> 可能會損毀。

BlockingCollection<T> 未設計為以非同步存取為考慮。 如果您的應用程式需要非同步產生者/取用者案例,請考慮改用 Channel<T>

建構函式

BlockingCollection<T>()

在無上限情況下,初始化 BlockingCollection<T> 類別的新執行個體。

BlockingCollection<T>(Int32)

在指定的上限情況下,初始化 BlockingCollection<T> 類別的新執行個體。

BlockingCollection<T>(IProducerConsumerCollection<T>)

在無上限情況下,使用提供的 BlockingCollection<T> 做為類別之基礎資料存放區,初始化 IProducerConsumerCollection<T> 類別的新執行個體。

BlockingCollection<T>(IProducerConsumerCollection<T>, Int32)

在指定上限情況下,使用提供的 BlockingCollection<T> 做為類別之基礎資料存放區,初始化 IProducerConsumerCollection<T> 類別的新執行個體。

屬性

BoundedCapacity

取得這個 BlockingCollection<T> 執行個體的界限容量。

Count

取得 BlockingCollection<T> 中所含的項目數。

IsAddingCompleted

取得值,表示這個 BlockingCollection<T> 是否標記為加入完成。

IsCompleted

取得值,表示這個 BlockingCollection<T> 是否標記為加入完成,而且是空的。

方法

Add(T)

將項目加入至 BlockingCollection<T>

Add(T, CancellationToken)

將項目加入至 BlockingCollection<T>

AddToAny(BlockingCollection<T>[], T)

將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。

AddToAny(BlockingCollection<T>[], T, CancellationToken)

將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。

CompleteAdding()

BlockingCollection<T> 執行個體標記為不再接受任何加入項目。

CopyTo(T[], Int32)

從目標陣列中的指定索引處開始,將 BlockingCollection<T> 執行個體中的所有項目複製到相容的一維陣列。

Dispose()

釋放 BlockingCollection<T> 類別目前的執行個體所使用的全部資源。

Dispose(Boolean)

釋放 BlockingCollection<T> 執行個體所使用的資源。

Equals(Object)

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

(繼承來源 Object)
GetConsumingEnumerable()

提供集合中項目的耗用 IEnumerable<T>

GetConsumingEnumerable(CancellationToken)

提供集合中項目的耗用 IEnumerable<T>

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Take()

BlockingCollection<T> 移除項目。

Take(CancellationToken)

BlockingCollection<T> 移除項目。

TakeFromAny(BlockingCollection<T>[], T)

從任何一個指定的 BlockingCollection<T> 執行個體取得項目。

TakeFromAny(BlockingCollection<T>[], T, CancellationToken)

當觀察指定的取消語彙基元時,接受任何一個指定之 BlockingCollection<T> 執行個體中的項目。

ToArray()

BlockingCollection<T> 執行個體,將其中項目複製到新陣列。

ToString()

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

(繼承來源 Object)
TryAdd(T)

嘗試將指定的項目加入至 BlockingCollection<T>

TryAdd(T, Int32)

嘗試在指定的時間週期內,將指定的項目加入 BlockingCollection<T>

TryAdd(T, Int32, CancellationToken)

當觀察取消語彙基元時,嘗試在指定的時間週期內,將指定的項目加入 BlockingCollection<T>

TryAdd(T, TimeSpan)

嘗試將指定的項目加入至 BlockingCollection<T>

TryAddToAny(BlockingCollection<T>[], T)

嘗試將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。

TryAddToAny(BlockingCollection<T>[], T, Int32)

嘗試將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。

TryAddToAny(BlockingCollection<T>[], T, Int32, CancellationToken)

嘗試將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。

TryAddToAny(BlockingCollection<T>[], T, TimeSpan)

當觀察指定的取消語彙基元時,嘗試將指定的項目加入任何一個指定的 BlockingCollection<T> 執行個體。

TryTake(T)

嘗試從 BlockingCollection<T> 移除項目。

TryTake(T, Int32)

嘗試在指定的時間週期內,從 BlockingCollection<T> 中移除項目。

TryTake(T, Int32, CancellationToken)

當觀察取消語彙基元時,嘗試在指定的時間週期內,從 BlockingCollection<T> 中移除項目。

TryTake(T, TimeSpan)

嘗試在指定的時間週期內,從 BlockingCollection<T> 中移除項目。

TryTakeFromAny(BlockingCollection<T>[], T)

嘗試從任何一個指定的 BlockingCollection<T> 執行個體移除項目。

TryTakeFromAny(BlockingCollection<T>[], T, Int32)

嘗試從任何一個指定的 BlockingCollection<T> 執行個體移除項目。

TryTakeFromAny(BlockingCollection<T>[], T, Int32, CancellationToken)

嘗試從任何一個指定的 BlockingCollection<T> 執行個體移除項目。

TryTakeFromAny(BlockingCollection<T>[], T, TimeSpan)

嘗試從任何一個指定的 BlockingCollection<T> 執行個體移除項目。

明確介面實作

ICollection.CopyTo(Array, Int32)

從目標陣列中的指定索引處開始,將 BlockingCollection<T> 執行個體中的所有項目複製到相容的一維陣列。

ICollection.IsSynchronized

取得值,這個值表示對 ICollection 的存取是否同步 (安全執行緒)。

ICollection.SyncRoot

取得可用以同步存取 ICollection 的物件。 不支援這個屬性。

IEnumerable.GetEnumerator()

提供集合中項目的 IEnumerator

IEnumerable<T>.GetEnumerator()

提供集合中項目的 IEnumerator<T>

擴充方法

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

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

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

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

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

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

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

根據輸入 DataTable 物件 (其中泛型參數 TDataRow) 傳回包含 IEnumerable<T> 物件複本的 DataRow

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

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRow

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

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRow

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

提供安全執行緒集合適用的封鎖和界限容量,這個集合會實作 IProducerConsumerCollection<T>

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

提供安全執行緒集合適用的封鎖和界限容量,這個集合會實作 IProducerConsumerCollection<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)

使用預設的相等比較子 (Comparer) 來判斷序列是否包含指定的項目。

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

提供安全執行緒集合適用的封鎖和界限容量,這個集合會實作 IProducerConsumerCollection<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>)

提供安全執行緒集合適用的封鎖和界限容量,這個集合會實作 IProducerConsumerCollection<T>

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)

傳回新的可列舉集合,其包含已省略來源集合最後 count 元素的所有 source 元素。

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

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

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

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

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

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

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

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

ToHashSet<TSource>(IEnumerable<TSource>)

IEnumerable<T> 建立 HashSet<T>

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

使用比較金鑰的 comparerIEnumerable<T> 建立 HashSet<T>

ToList<TSource>(IEnumerable<TSource>)

IEnumerable<T> 建立 List<T>

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

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

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

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

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

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

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

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

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

從兩個指定序列中的元素產生一系列元組。

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

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

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

在來源集合中,從每一個節點的父節點移除這些節點。

適用於

執行緒安全性

Dispose 方法不是安全線程。 的所有其他公用和受保護成員 BlockingCollection<T> 都是安全線程,而且可以從多個執行緒同時使用。

另請參閱