BindingList<T> 類別

定義

提供支持數據系結的泛型集合。

generic <typename T>
public ref class BindingList : System::Collections::ObjectModel::Collection<T>, System::ComponentModel::IBindingList, System::ComponentModel::ICancelAddNew, System::ComponentModel::IRaiseItemChangedEvents
[System.Serializable]
public class BindingList<T> : System.Collections.ObjectModel.Collection<T>, System.ComponentModel.IBindingList, System.ComponentModel.ICancelAddNew, System.ComponentModel.IRaiseItemChangedEvents
public class BindingList<T> : System.Collections.ObjectModel.Collection<T>, System.ComponentModel.IBindingList, System.ComponentModel.ICancelAddNew, System.ComponentModel.IRaiseItemChangedEvents
[<System.Serializable>]
type BindingList<'T> = class
    inherit Collection<'T>
    interface IBindingList
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICancelAddNew
    interface IRaiseItemChangedEvents
type BindingList<'T> = class
    inherit Collection<'T>
    interface ICollection
    interface IEnumerable
    interface IList
    interface IBindingList
    interface ICancelAddNew
    interface IRaiseItemChangedEvents
Public Class BindingList(Of T)
Inherits Collection(Of T)
Implements IBindingList, ICancelAddNew, IRaiseItemChangedEvents

類型參數

T

清單中的項目類型。

繼承
BindingList<T>
屬性
實作

範例

以下範例示範綁定到 BindingList<T> 包含業務物件的元件。 這是一個包含方法 Main 的完整範例。

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace BindingListOfTExamples;

public partial class Form1 : Form
{
    readonly TextBox textBox2;
    readonly ListBox listBox1;
    readonly Button button1;
    readonly TextBox textBox1;
    readonly Random randomNumber = new();

    public Form1()
    {
        AutoScaleMode = AutoScaleMode.Font;
        textBox1 = new TextBox();
        textBox2 = new TextBox();
        listBox1 = new ListBox();
        button1 = new Button();
        textBox1.Location = new Point(169, 26);
        textBox1.Size = new Size(100, 20);
        textBox1.Text = "Bracket";
        textBox2.Location = new Point(169, 57);
        textBox2.ReadOnly = true;
        textBox2.Size = new Size(100, 20);
        textBox2.Text = "4343";
        listBox1.FormattingEnabled = true;
        listBox1.Location = new Point(12, 12);
        listBox1.Size = new Size(120, 95);
        button1.Location = new Point(180, 83);
        button1.Size = new Size(75, 23);
        button1.Text = "Add New Item";
        button1.Click += button1_Click;
        ClientSize = new Size(292, 266);
        Controls.Add(button1);
        Controls.Add(listBox1);
        Controls.Add(textBox2);
        Controls.Add(textBox1);
        Text = "Parts Form";
        Load += Form1_Load;
    }

    void Form1_Load(object sender, EventArgs e)
    {
        InitializeListOfParts();
        listBox1.DataSource = listOfParts;
        listBox1.DisplayMember = "PartName";
        listOfParts.AddingNew += listOfParts_AddingNew;
        listOfParts.ListChanged += listOfParts_ListChanged;
    }

    // Declare a new BindingListOfT with the Part business object.
    BindingList<Part> listOfParts;
    void InitializeListOfParts()
    {
        // Create the new BindingList of Part type.
        listOfParts = new BindingList<Part>
        {
            // Allow new parts to be added, but not removed once committed.        
            AllowNew = true,
            AllowRemove = false,

            // Raise ListChanged events when new parts are added.
            RaiseListChangedEvents = true,

            // Do not allow parts to be edited.
            AllowEdit = false
        };

        // Add a couple of parts to the list.
        listOfParts.Add(new Part("Widget", 1234));
        listOfParts.Add(new Part("Gadget", 5647));
    }

    // Create a new part from the text in the two text boxes.
    void listOfParts_AddingNew(object sender, AddingNewEventArgs e) => e.NewObject = new Part(textBox1.Text, int.Parse(textBox2.Text));

    // Add the new part unless the part number contains
    // spaces. In that case cancel the add.
    void button1_Click(object sender, EventArgs e)
    {
        Part newPart = listOfParts.AddNew();

        if (newPart.PartName.Contains(' '))
        {
            _ = MessageBox.Show("Part names cannot contain spaces.");
            listOfParts.CancelNew(listOfParts.IndexOf(newPart));
        }
        else
        {
            textBox2.Text = randomNumber.Next(9999).ToString();
            textBox1.Text = "Enter part name";
        }
    }

    void listOfParts_ListChanged(object sender, ListChangedEventArgs e) => MessageBox.Show(e.ListChangedType.ToString());

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}

// A simple business object for example purposes.
public class Part
{
    public Part() { }
    public Part(string nameForPart, int numberForPart)
    {
        PartName = nameForPart;
        PartNumber = numberForPart;
    }

    public string PartName { get; set; }

    public int PartNumber { get; set; }
}

Option Explicit On
Option Strict On
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Class Form1
    Inherits Form

    Private textBox2 As TextBox
    Private listBox1 As ListBox
    Private WithEvents button1 As Button
    Private textBox1 As TextBox
    Private randomNumber As New Random()

    Public Sub New()
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.textBox1 = New System.Windows.Forms.TextBox()
        Me.textBox2 = New System.Windows.Forms.TextBox()
        Me.listBox1 = New System.Windows.Forms.ListBox()
        Me.button1 = New System.Windows.Forms.Button()
        Me.textBox1.Location = New System.Drawing.Point(169, 26)
        Me.textBox1.Size = New System.Drawing.Size(100, 20)
        Me.textBox1.Text = "Bracket"
        Me.textBox2.Location = New System.Drawing.Point(169, 57)
        Me.textBox2.ReadOnly = True
        Me.textBox2.Size = New System.Drawing.Size(100, 20)
        Me.textBox2.Text = "4343"
        Me.listBox1.FormattingEnabled = True
        Me.listBox1.Location = New System.Drawing.Point(12, 12)
        Me.listBox1.Size = New System.Drawing.Size(120, 95)
        Me.button1.Location = New System.Drawing.Point(180, 83)
        Me.button1.Size = New System.Drawing.Size(75, 23)
        Me.button1.Text = "Add New Item"
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.button1)
        Me.Controls.Add(Me.listBox1)
        Me.Controls.Add(Me.textBox2)
        Me.Controls.Add(Me.textBox1)
        Me.Text = "Parts Form"
        AddHandler Me.Load, AddressOf Form1_Load

    End Sub

    Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        InitializeListOfParts()
        listBox1.DataSource = listOfParts
        listBox1.DisplayMember = "PartName"
    End Sub

    ' Declare a new BindingListOfT with the Part business object.
    Private WithEvents listOfParts As BindingList(Of Part)

    Private Sub InitializeListOfParts()

        ' Create the new BindingList of Part type.
        listOfParts = New BindingList(Of Part)

        ' Allow new parts to be added, but not removed once committed.        
        listOfParts.AllowNew = True
        listOfParts.AllowRemove = False

        ' Raise ListChanged events when new parts are added.
        listOfParts.RaiseListChangedEvents = True

        ' Do not allow parts to be edited.
        listOfParts.AllowEdit = False

        ' Add a couple of parts to the list.
        listOfParts.Add(New Part("Widget", 1234))
        listOfParts.Add(New Part("Gadget", 5647))

    End Sub

    ' Create a new part from the text in the two text boxes.
    Private Sub listOfParts_AddingNew(ByVal sender As Object, _
        ByVal e As AddingNewEventArgs) Handles listOfParts.AddingNew
        e.NewObject = New Part(textBox1.Text, Integer.Parse(textBox2.Text))

    End Sub


    ' Add the new part unless the part number contains
    ' spaces. In that case cancel the add.
    Private Sub button1_Click(ByVal sender As Object, _
        ByVal e As EventArgs) Handles button1.Click

        Dim newPart As Part = listOfParts.AddNew()

        If newPart.PartName.Contains(" ") Then
            MessageBox.Show("Part names cannot contain spaces.")
            listOfParts.CancelNew(listOfParts.IndexOf(newPart))
        Else
            textBox2.Text = randomNumber.Next(9999).ToString()
            textBox1.Text = "Enter part name"
        End If

    End Sub

    <STAThread()> _
    Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New Form1())

    End Sub
End Class

' A simple business object for example purposes.
Public Class Part
    Private name As String
    Private number As Integer

    Public Sub New()
    End Sub

    Public Sub New(ByVal nameForPart As String, _
        ByVal numberForPart As Integer)
        PartName = nameForPart
        PartNumber = numberForPart

    End Sub


    Public Property PartName() As String
        Get
            Return name
        End Get
        Set(ByVal value As String)
            name = Value
        End Set
    End Property

    Public Property PartNumber() As Integer
        Get
            Return number
        End Get
        Set(ByVal value As Integer)
            number = Value
        End Set
    End Property
End Class

備註

BindingList<T> 類別可作為基底類別,建立雙向資料綁定機制。 BindingList<T> 提供一個具體且通用的 IBindingList 介面實作。 這是實現完整IBindingList介面的替代方案,因為完整介面因 、 IEditableObjectCurrencyManager之間的微妙互動IBindingList而較為困難。 然而,典型的解決方案程式設計師會使用提供資料綁定功能的類別,例如 BindingSource,而非直接使用 BindingList<T>

BindingList<T> 透過可 AddNew 擴充方法支援工廠建立的實例。 (類似的可擴展性也存在於其他類別中,例如 BindingSource)此外,由於此類別實作了介面,ICancelAddNew它能透過 and CancelNew 方法對新項目EndNew進行交易提交或回滾。

建構函式

名稱 Description
BindingList<T>()

使用預設值初始化該類別的新實例 BindingList<T>

BindingList<T>(IList<T>)

初始化一個新的類別實例 BindingList<T> ,使用指定的清單。

屬性

名稱 Description
AllowEdit

取得或設定一個值,指示列表中的項目是否可以被編輯。

AllowNew

會取得或設定一個值,指示你是否可以用該 AddNew() 方法將項目加入清單。

AllowRemove

會取得或設定一個值,表示你是否可以從收藏中移除項目。

Count

取得實際包含於 Collection<T>的元素數量。

(繼承來源 Collection<T>)
IsSortedCore

會獲得一個值,表示清單是否已排序。

Item[Int32]

取得或設定位於指定索引處的專案。

(繼承來源 Collection<T>)
Items

會被 IList<T> 包裹在 Collection<T>.

(繼承來源 Collection<T>)
RaiseListChangedEvents

取得或設定一個值,指示列表中新增或移除項目是否會 ListChanged 引發事件。

SortDirectionCore

它會得到清單排序的方向。

SortPropertyCore

若排序實作於衍生類別,則取得用於排序清單的屬性描述符;否則,返回 null

SupportsChangeNotificationCore

會獲得一個值,表示事件是否 ListChanged 已啟用。

SupportsSearchingCore

會獲得一個值,表示該清單是否支援搜尋。

SupportsSortingCore

會獲得一個值,表示該清單是否支援排序。

方法

名稱 Description
Add(T)

在 的末尾 Collection<T>加上一個物件。

(繼承來源 Collection<T>)
AddNew()

新增一個物品到收藏中。

AddNewCore()

在收藏的最後新增一項物品。

ApplySortCore(PropertyDescriptor, ListSortDirection)

若在衍生類別中被覆寫,則排序項目;否則,會拋出 NotSupportedException

CancelNew(Int32)

丟棄一個待處理的新物品。

Clear()

移除所有元素。Collection<T>

(繼承來源 Collection<T>)
ClearItems()

移除集合中的所有元素。

Contains(T)

判斷專案是否在 Collection<T>中。

(繼承來源 Collection<T>)
CopyTo(T[], Int32)

從目標陣列指定的索引開始,將整個 Collection<T> 複製到相容的一維 Array

(繼承來源 Collection<T>)
EndNew(Int32)

將一個待處理的新項目提交到收藏中。

Equals(Object)

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

(繼承來源 Object)
FindCore(PropertyDescriptor, Object)

搜尋具有指定屬性描述符且值指定的項目索引,若搜尋是在導出類別中實作;否則,則為 NotSupportedException

GetEnumerator()

回傳一個遍歷 的 Collection<T>枚舉子。

(繼承來源 Collection<T>)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IndexOf(T)

搜尋指定物件,並回傳整個 Collection<T>中首次出現的零基索引。

(繼承來源 Collection<T>)
Insert(Int32, T)

在指定的索引處插入一個元素 Collection<T>

(繼承來源 Collection<T>)
InsertItem(Int32, T)

在指定的索引中插入指定的項目。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
OnAddingNew(AddingNewEventArgs)

引發 AddingNew 事件。

OnListChanged(ListChangedEventArgs)

引發 ListChanged 事件。

Remove(T)

移除特定物件 Collection<T>首次出現的 。

(繼承來源 Collection<T>)
RemoveAt(Int32)

移除位於指定索引 Collection<T>的元素。

(繼承來源 Collection<T>)
RemoveItem(Int32)

拿掉位於指定索引處的專案。

RemoveSortCore()

若排序實作於導出類別,則移除 的 ApplySortCore(PropertyDescriptor, ListSortDirection) 排序;否則,則 提升 NotSupportedException

ResetBindings()

引發 ListChanged 一個類型的 Reset事件。

ResetItem(Int32)

在指定位置為該項目提出 ListChanged 一個類型的 ItemChanged 事件。

SetItem(Int32, T)

將位於指定索引處的專案取代為指定的專案。

ToString()

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

(繼承來源 Object)

事件

名稱 Description
AddingNew

發生在項目加入清單之前。

ListChanged

當清單或清單中的項目改變時,會發生這種情況。

明確介面實作

名稱 Description
IBindingList.AddIndex(PropertyDescriptor)

關於此成員的描述,請參見 AddIndex(PropertyDescriptor)

IBindingList.AddNew()

新增一項物品到清單中。 如需詳細資訊,請參閱AddNew()

IBindingList.AllowEdit

會獲得一個值,表示清單中的項目是否可以被編輯。

IBindingList.AllowNew

會取得一個值,表示是否可以用該 AddNew() 方法將新項目加入清單。

IBindingList.AllowRemove

會有一個值,表示項目是否可以從清單中移除。

IBindingList.ApplySort(PropertyDescriptor, ListSortDirection)

根據 a PropertyDescriptor 和 a ListSortDirection來排序清單。 關於此成員的完整描述,請參見 ApplySort(PropertyDescriptor, ListSortDirection)

IBindingList.Find(PropertyDescriptor, Object)

關於此成員的描述,請參見 Find(PropertyDescriptor, Object)

IBindingList.IsSorted

關於此成員的描述,請參見 IsSorted

IBindingList.RemoveIndex(PropertyDescriptor)

關於此成員的描述,請參見 RemoveIndex(PropertyDescriptor)

IBindingList.RemoveSort()

關於此成員的描述,請參見 RemoveSort()

IBindingList.SortDirection

關於此成員的描述,請參見 SortDirection

IBindingList.SortProperty

關於此成員的描述,請參見 SortProperty

IBindingList.SupportsChangeNotification

關於此成員的描述,請參見 SupportsChangeNotification

IBindingList.SupportsSearching

關於此成員的描述,請參見 SupportsSearching

IBindingList.SupportsSorting

關於此成員的描述,請參見 SupportsSorting

ICollection.CopyTo(Array, Int32)

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

(繼承來源 Collection<T>)
ICollection.IsSynchronized

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

(繼承來源 Collection<T>)
ICollection.SyncRoot

取得一個物件,可用來同步存取 ICollection

(繼承來源 Collection<T>)
ICollection<T>.IsReadOnly

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

(繼承來源 Collection<T>)
IEnumerable.GetEnumerator()

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

(繼承來源 Collection<T>)
IList.Add(Object)

將一個項目加入 IList

(繼承來源 Collection<T>)
IList.Contains(Object)

判斷是否 IList 包含特定值。

(繼承來源 Collection<T>)
IList.IndexOf(Object)

決定特定項目的 IList索引。

(繼承來源 Collection<T>)
IList.Insert(Int32, Object)

在指定的索引處插入一個項目 IList

(繼承來源 Collection<T>)
IList.IsFixedSize

會得到一個值,表示 是否 IList 具有固定大小。

(繼承來源 Collection<T>)
IList.IsReadOnly

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

(繼承來源 Collection<T>)
IList.Item[Int32]

取得或設定位於指定索引處的專案。

(繼承來源 Collection<T>)
IList.Remove(Object)

移除特定物件 IList首次出現的 。

(繼承來源 Collection<T>)
IRaiseItemChangedEvents.RaisesItemChangedEvents

取得一個值,表示項目屬性值是否改變,並引發 ListChanged 類型的 ItemChanged事件。 此成員無法在導出類別中被覆寫。

擴充方法

名稱 Description
Aggregate<TSource,TAccumulate,TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, Func<TAccumulate,TResult>)

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

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

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

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

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

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

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

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

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

Ancestors<T>(IEnumerable<T>)

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

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

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

Any<TSource>(IEnumerable<TSource>)

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

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

將值附加至序列結尾。

AsEnumerable<TSource>(IEnumerable<TSource>)

傳回 IEnumerable<T> 類型的輸入。

AsParallel(IEnumerable)

啟用查詢的平行處理。

AsParallel<TSource>(IEnumerable<TSource>)

啟用查詢的平行處理。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

AsQueryable<TElement>(IEnumerable<TElement>)

將泛型 IEnumerable<T> 轉換成泛型 IQueryable<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 的項目轉換成指定的型別。

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

串連兩個序列。

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

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

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

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

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

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

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

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

CopyToDataTable<T>(IEnumerable<T>)

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

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

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

Count<TSource>(IEnumerable<TSource>)

傳回序列中的項目數目。

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

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

DefaultIfEmpty<TSource>(IEnumerable<TSource>)

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

DescendantNodes<T>(IEnumerable<T>)

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

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

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

Descendants<T>(IEnumerable<T>)

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

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

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

Distinct<TSource>(IEnumerable<TSource>)

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

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

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

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

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

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

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

Elements<T>(IEnumerable<T>)

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

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

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

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

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

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

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

First<TSource>(IEnumerable<TSource>)

傳回序列的第一個專案。

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

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

FirstOrDefault<TSource>(IEnumerable<TSource>)

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

GroupBy<TSource,TKey,TElement,TResult>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource,TElement>, Func<TKey,IEnumerable<TElement>, 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>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

InDocumentOrder<T>(IEnumerable<T>)

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

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

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

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

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

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

根據匹配的鍵數關聯兩個序列的元素。 指定的 IEqualityComparer<T> 可用來比較索引鍵。

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

根據匹配的鍵數關聯兩個序列的元素。 默認相等比較子可用來比較索引鍵。

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

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

Last<TSource>(IEnumerable<TSource>)

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

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

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

LastOrDefault<TSource>(IEnumerable<TSource>)

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

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

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

LongCount<TSource>(IEnumerable<TSource>)

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

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

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

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>(IEnumerable<TSource>)

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

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

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

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>(IEnumerable<TSource>)

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

Nodes<T>(IEnumerable<T>)

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

OfType<TResult>(IEnumerable)

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

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

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

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

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

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

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

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

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

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

將值加入序列的開頭。

Remove<T>(IEnumerable<T>)

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

Reverse<TSource>(IEnumerable<TSource>)

反轉序列中項目的順序。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Single<TSource>(IEnumerable<TSource>)

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

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

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

SingleOrDefault<TSource>(IEnumerable<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)

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

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

回傳一個新的可枚舉集合,包含 的count最後元素source

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,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, 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>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

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

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

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

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

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

ToHashSet<TSource>(IEnumerable<TSource>)

HashSet<T>建立 IEnumerable<T>

ToList<TSource>(IEnumerable<TSource>)

List<T>建立 IEnumerable<T>

ToLookup<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, 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>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

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

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

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

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

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

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

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

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

根據述詞篩選值序列。

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

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

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

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

適用於

另請參閱