KeyedCollection<TKey,TItem> Klasa

Definicja

Udostępnia abstrakcyjną klasę bazową dla kolekcji, której klucze są osadzone w wartościach.

generic <typename TKey, typename TItem>
public ref class KeyedCollection abstract : System::Collections::ObjectModel::Collection<TItem>
public abstract class KeyedCollection<TKey,TItem> : System.Collections.ObjectModel.Collection<TItem>
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public abstract class KeyedCollection<TKey,TItem> : System.Collections.ObjectModel.Collection<TItem>
type KeyedCollection<'Key, 'Item> = class
    inherit Collection<'Item>
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type KeyedCollection<'Key, 'Item> = class
    inherit Collection<'Item>
Public MustInherit Class KeyedCollection(Of TKey, TItem)
Inherits Collection(Of TItem)

Parametry typu

TKey

Typ kluczy w kolekcji.

TItem

Typ elementów w kolekcji.

Dziedziczenie
Collection<TItem>
KeyedCollection<TKey,TItem>
Pochodne
Atrybuty

Przykłady

Ten rozdział zawiera dwa przykłady kodu. W pierwszym przykładzie pokazano minimalny kod wymagany do wyprowadzenia z KeyedCollection<TKey,TItem>klasy i demonstruje wiele odziedziczonych metod. W drugim przykładzie pokazano, jak zastąpić chronione metody w celu zapewnienia zachowania niestandardowego KeyedCollection<TKey,TItem> .

Przykład 1

W tym przykładzie kodu przedstawiono minimalny kod niezbędny do utworzenia klasy kolekcji z KeyedCollection<TKey,TItem>klasy : przesłanianie GetKeyForItem metody i dostarczanie publicznego konstruktora, który deleguje do konstruktora klasy bazowej. W przykładzie kodu pokazano również wiele właściwości i metod dziedziczone z KeyedCollection<TKey,TItem> klas i Collection<T> .

Klasa SimpleOrder jest bardzo prostą listą requisition zawierającą OrderItem obiekty, z których każda reprezentuje element liniowy w kolejności. Klucz funkcji OrderItem jest niezmienny, co jest ważnym zagadnieniem dla klas, które pochodzą z klasy KeyedCollection<TKey,TItem>. Aby zapoznać się z przykładem kodu, który używa kluczy modyfikowalnych, zobacz ChangeItemKey.

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

// This class represents a simple line item in an order. All the 
// values are immutable except quantity.
// 
public ref class OrderItem
{
private:
    int _quantity;
    
public:
    initonly int PartNumber;
    initonly String^ Description;
    initonly double UnitPrice;
    
    OrderItem(int partNumber, String^ description, 
        int quantity, double unitPrice)
    {
        this->PartNumber = partNumber;
        this->Description = description;
        this->Quantity = quantity;
        this->UnitPrice = unitPrice;
    } 
    
    property int Quantity    
    {
        int get() { return _quantity; }
        void set(int value)
        {
            if (value < 0)
                throw gcnew ArgumentException("Quantity cannot be negative.");
            
            _quantity = value;
        }
    }
        
    virtual String^ ToString() override 
    {
        return String::Format(
            "{0,9} {1,6} {2,-12} at {3,8:#,###.00} = {4,10:###,###.00}", 
            PartNumber, _quantity, Description, UnitPrice, 
            UnitPrice * _quantity);
    }
};

// This class represents a very simple keyed list of OrderItems,
// inheriting most of its behavior from the KeyedCollection and 
// Collection classes. The immediate base class is the constructed
// type KeyedCollection<int, OrderItem>. When you inherit
// from KeyedCollection, the second generic type argument is the 
// type that you want to store in the collection -- in this case
// OrderItem. The first type argument is the type that you want
// to use as a key. Its values must be calculated from OrderItem; 
// in this case it is the int field PartNumber, so SimpleOrder
// inherits KeyedCollection<int, OrderItem>.
//
public ref class SimpleOrder : KeyedCollection<int, OrderItem^>
{
    // The parameterless constructor of the base class creates a 
    // KeyedCollection with an internal dictionary. For this code 
    // example, no other constructors are exposed.
    //
public:
    SimpleOrder() {}
    
    // This is the only method that absolutely must be overridden,
    // because without it the KeyedCollection cannot extract the
    // keys from the items. The input parameter type is the 
    // second generic type argument, in this case OrderItem, and 
    // the return value type is the first generic type argument,
    // in this case int.
    //
protected:
    virtual int GetKeyForItem(OrderItem^ item) override 
    {
        // In this example, the key is the part number.
        return item->PartNumber;
    }
};

public ref class Demo
{    
public:
    static void Main()
    {
        SimpleOrder^ weekly = gcnew SimpleOrder();

        // The Add method, inherited from Collection, takes OrderItem.
        //
        weekly->Add(gcnew OrderItem(110072674, "Widget", 400, 45.17));
        weekly->Add(gcnew OrderItem(110072675, "Sprocket", 27, 5.3));
        weekly->Add(gcnew OrderItem(101030411, "Motor", 10, 237.5));
        weekly->Add(gcnew OrderItem(110072684, "Gear", 175, 5.17));
        
        Display(weekly);
    
        // The Contains method of KeyedCollection takes the key, 
        // type, in this case int.
        //
        Console::WriteLine("\nContains(101030411): {0}", 
            weekly->Contains(101030411));

        // The default Item property of KeyedCollection takes a key.
        //
        Console::WriteLine("\nweekly(101030411)->Description: {0}", 
            weekly[101030411]->Description);

        // The Remove method of KeyedCollection takes a key.
        //
        Console::WriteLine("\nRemove(101030411)");
        weekly->Remove(101030411);
        Display(weekly);

        // The Insert method, inherited from Collection, takes an 
        // index and an OrderItem.
        //
        Console::WriteLine("\nInsert(2, New OrderItem(...))");
        weekly->Insert(2, gcnew OrderItem(111033401, "Nut", 10, .5));
        Display(weekly);

        // The default Item property is overloaded. One overload comes
        // from KeyedCollection<int, OrderItem>; that overload
        // is read-only, and takes Integer because it retrieves by key. 
        // The other overload comes from Collection<OrderItem>, the 
        // base class of KeyedCollection<int, OrderItem>; it 
        // retrieves by index, so it also takes an Integer. The compiler
        // uses the most-derived overload, from KeyedCollection, so the
        // only way to access SimpleOrder by index is to cast it to
        // Collection<OrderItem>. Otherwise the index is interpreted
        // as a key, and KeyNotFoundException is thrown.
        //
        Collection<OrderItem^>^ coweekly = weekly;
        Console::WriteLine("\ncoweekly[2].Description: {0}", 
            coweekly[2]->Description);
 
        Console::WriteLine("\ncoweekly[2] = gcnew OrderItem(...)");
        coweekly[2] = gcnew OrderItem(127700026, "Crank", 27, 5.98);

        OrderItem^ temp = coweekly[2];

        // The IndexOf method inherited from Collection<OrderItem> 
        // takes an OrderItem instead of a key
        // 
        Console::WriteLine("\nIndexOf(temp): {0}", weekly->IndexOf(temp));

        // The inherited Remove method also takes an OrderItem.
        //
        Console::WriteLine("\nRemove(temp)");
        weekly->Remove(temp);
        Display(weekly);

        Console::WriteLine("\nRemoveAt(0)");
        weekly->RemoveAt(0);
        Display(weekly);

    }
    
private:
    static void Display(SimpleOrder^ order)
    {
        Console::WriteLine();
        for each( OrderItem^ item in order )
        {
            Console::WriteLine(item);
        }
    }
};

void main()
{
    Demo::Main();
}

/* This code example produces the following output:

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
101030411     10 Motor        at   237.50 =   2,375.00
110072684    175 Gear         at     5.17 =     904.75

Contains(101030411): True

weekly(101030411)->Description: Motor

Remove(101030411)

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
110072684    175 Gear         at     5.17 =     904.75

Insert(2, New OrderItem(...))

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
111033401     10 Nut          at      .50 =       5.00
110072684    175 Gear         at     5.17 =     904.75

coweekly(2)->Description: Nut

coweekly[2] = gcnew OrderItem(...)

IndexOf(temp): 2

Remove(temp)

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
110072684    175 Gear         at     5.17 =     904.75

RemoveAt(0)

110072675     27 Sprocket     at     5.30 =     143.10
110072684    175 Gear         at     5.17 =     904.75
 */
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

// This class represents a very simple keyed list of OrderItems,
// inheriting most of its behavior from the KeyedCollection and
// Collection classes. The immediate base class is the constructed
// type KeyedCollection<int, OrderItem>. When you inherit
// from KeyedCollection, the second generic type argument is the
// type that you want to store in the collection -- in this case
// OrderItem. The first type argument is the type that you want
// to use as a key. Its values must be calculated from OrderItem;
// in this case it is the int field PartNumber, so SimpleOrder
// inherits KeyedCollection<int, OrderItem>.
//
public class SimpleOrder : KeyedCollection<int, OrderItem>
{

    // This is the only method that absolutely must be overridden,
    // because without it the KeyedCollection cannot extract the
    // keys from the items. The input parameter type is the
    // second generic type argument, in this case OrderItem, and
    // the return value type is the first generic type argument,
    // in this case int.
    //
    protected override int GetKeyForItem(OrderItem item)
    {
        // In this example, the key is the part number.
        return item.PartNumber;
    }
}

public class Demo
{
    public static void Main()
    {
        SimpleOrder weekly = new SimpleOrder();

        // The Add method, inherited from Collection, takes OrderItem.
        //
        weekly.Add(new OrderItem(110072674, "Widget", 400, 45.17));
        weekly.Add(new OrderItem(110072675, "Sprocket", 27, 5.3));
        weekly.Add(new OrderItem(101030411, "Motor", 10, 237.5));
        weekly.Add(new OrderItem(110072684, "Gear", 175, 5.17));

        Display(weekly);

        // The Contains method of KeyedCollection takes the key,
        // type, in this case int.
        //
        Console.WriteLine("\nContains(101030411): {0}",
            weekly.Contains(101030411));

        // The default Item property of KeyedCollection takes a key.
        //
        Console.WriteLine("\nweekly[101030411].Description: {0}",
            weekly[101030411].Description);

        // The Remove method of KeyedCollection takes a key.
        //
        Console.WriteLine("\nRemove(101030411)");
        weekly.Remove(101030411);
        Display(weekly);

        // The Insert method, inherited from Collection, takes an
        // index and an OrderItem.
        //
        Console.WriteLine("\nInsert(2, New OrderItem(...))");
        weekly.Insert(2, new OrderItem(111033401, "Nut", 10, .5));
        Display(weekly);

        // The default Item property is overloaded. One overload comes
        // from KeyedCollection<int, OrderItem>; that overload
        // is read-only, and takes Integer because it retrieves by key.
        // The other overload comes from Collection<OrderItem>, the
        // base class of KeyedCollection<int, OrderItem>; it
        // retrieves by index, so it also takes an Integer. The compiler
        // uses the most-derived overload, from KeyedCollection, so the
        // only way to access SimpleOrder by index is to cast it to
        // Collection<OrderItem>. Otherwise the index is interpreted
        // as a key, and KeyNotFoundException is thrown.
        //
        Collection<OrderItem> coweekly = weekly;
        Console.WriteLine("\ncoweekly[2].Description: {0}",
            coweekly[2].Description);

        Console.WriteLine("\ncoweekly[2] = new OrderItem(...)");
        coweekly[2] = new OrderItem(127700026, "Crank", 27, 5.98);

        OrderItem temp = coweekly[2];

        // The IndexOf method inherited from Collection<OrderItem>
        // takes an OrderItem instead of a key
        //
        Console.WriteLine("\nIndexOf(temp): {0}", weekly.IndexOf(temp));

        // The inherited Remove method also takes an OrderItem.
        //
        Console.WriteLine("\nRemove(temp)");
        weekly.Remove(temp);
        Display(weekly);

        Console.WriteLine("\nRemoveAt(0)");
        weekly.RemoveAt(0);
        Display(weekly);
    }

    private static void Display(SimpleOrder order)
    {
        Console.WriteLine();
        foreach( OrderItem item in order )
        {
            Console.WriteLine(item);
        }
    }
}

// This class represents a simple line item in an order. All the
// values are immutable except quantity.
//
public class OrderItem
{
    public readonly int PartNumber;
    public readonly string Description;
    public readonly double UnitPrice;

    private int _quantity = 0;

    public OrderItem(int partNumber, string description,
        int quantity, double unitPrice)
    {
        this.PartNumber = partNumber;
        this.Description = description;
        this.Quantity = quantity;
        this.UnitPrice = unitPrice;
    }

    public int Quantity
    {
        get { return _quantity; }
        set
        {
            if (value<0)
                throw new ArgumentException("Quantity cannot be negative.");

            _quantity = value;
        }
    }

    public override string ToString()
    {
        return String.Format(
            "{0,9} {1,6} {2,-12} at {3,8:#,###.00} = {4,10:###,###.00}",
            PartNumber, _quantity, Description, UnitPrice,
            UnitPrice * _quantity);
    }
}

/* This code example produces the following output:

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
101030411     10 Motor        at   237.50 =   2,375.00
110072684    175 Gear         at     5.17 =     904.75

Contains(101030411): True

weekly[101030411].Description: Motor

Remove(101030411)

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
110072684    175 Gear         at     5.17 =     904.75

Insert(2, New OrderItem(...))

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
111033401     10 Nut          at      .50 =       5.00
110072684    175 Gear         at     5.17 =     904.75

coweekly[2].Description: Nut

coweekly[2] = new OrderItem(...)

IndexOf(temp): 2

Remove(temp)

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
110072684    175 Gear         at     5.17 =     904.75

RemoveAt(0)

110072675     27 Sprocket     at     5.30 =     143.10
110072684    175 Gear         at     5.17 =     904.75
 */
Imports System.Collections.Generic
Imports System.Collections.ObjectModel

' This class represents a very simple keyed list of OrderItems,
' inheriting most of its behavior from the KeyedCollection and 
' Collection classes. The immediate base class is the constructed
' type KeyedCollection(Of Integer, OrderItem). When you inherit
' from KeyedCollection, the second generic type argument is the 
' type that you want to store in the collection -- in this case
' OrderItem. The first generic argument is the type that you want
' to use as a key. Its values must be calculated from OrderItem; 
' in this case it is the Integer field PartNumber, so SimpleOrder
' inherits KeyedCollection(Of Integer, OrderItem).
'
Public Class SimpleOrder
    Inherits KeyedCollection(Of Integer, OrderItem)


    ' This is the only method that absolutely must be overridden,
    ' because without it the KeyedCollection cannot extract the
    ' keys from the items. The input parameter type is the 
    ' second generic type argument, in this case OrderItem, and 
    ' the return value type is the first generic type argument,
    ' in this case Integer.
    '
    Protected Overrides Function GetKeyForItem( _
        ByVal item As OrderItem) As Integer

        ' In this example, the key is the part number.
        Return item.PartNumber   
    End Function

End Class

Public Class Demo
    
    Public Shared Sub Main() 
        Dim weekly As New SimpleOrder()

        ' The Add method, inherited from Collection, takes OrderItem.
        '
        weekly.Add(New OrderItem(110072674, "Widget", 400, 45.17))
        weekly.Add(New OrderItem(110072675, "Sprocket", 27, 5.3))
        weekly.Add(New OrderItem(101030411, "Motor", 10, 237.5))
        weekly.Add(New OrderItem(110072684, "Gear", 175, 5.17))
        
        Display(weekly)
    
        ' The Contains method of KeyedCollection takes TKey.
        '
        Console.WriteLine(vbLf & "Contains(101030411): {0}", _
            weekly.Contains(101030411))

        ' The default Item property of KeyedCollection takes the key
        ' type, Integer.
        '
        Console.WriteLine(vbLf & "weekly(101030411).Description: {0}", _
            weekly(101030411).Description)

        ' The Remove method of KeyedCollection takes a key.
        '
        Console.WriteLine(vbLf & "Remove(101030411)")
        weekly.Remove(101030411)
        Display(weekly)

        ' The Insert method, inherited from Collection, takes an 
        ' index and an OrderItem.
        '
        Console.WriteLine(vbLf & "Insert(2, New OrderItem(...))")
        weekly.Insert(2, New OrderItem(111033401, "Nut", 10, .5))
        Display(weekly)

        ' The default Item property is overloaded. One overload comes
        ' from KeyedCollection(Of Integer, OrderItem); that overload
        ' is read-only, and takes Integer because it retrieves by key. 
        ' The other overload comes from Collection(Of OrderItem), the 
        ' base class of KeyedCollection(Of Integer, OrderItem); it 
        ' retrieves by index, so it also takes an Integer. The compiler
        ' uses the most-derived overload, from KeyedCollection, so the
        ' only way to access SimpleOrder by index is to cast it to
        ' Collection(Of OrderItem). Otherwise the index is interpreted
        ' as a key, and KeyNotFoundException is thrown.
        '
        Dim coweekly As Collection(Of OrderItem) = weekly
        Console.WriteLine(vbLf & "coweekly(2).Description: {0}", _
            coweekly(2).Description)
 
        Console.WriteLine(vbLf & "coweekly(2) = New OrderItem(...)")
        coweekly(2) = New OrderItem(127700026, "Crank", 27, 5.98)

        Dim temp As OrderItem = coweekly(2)

        ' The IndexOf method, inherited from Collection(Of OrderItem), 
        ' takes an OrderItem instead of a key.
        ' 
        Console.WriteLine(vbLf & "IndexOf(temp): {0}", _
            weekly.IndexOf(temp))

        ' The inherited Remove method also takes an OrderItem.
        '
        Console.WriteLine(vbLf & "Remove(temp)")
        weekly.Remove(temp)
        Display(weekly)

        Console.WriteLine(vbLf & "RemoveAt(0)")
        weekly.RemoveAt(0)
        Display(weekly)

    End Sub
    
    Private Shared Sub Display(ByVal order As SimpleOrder) 
        Console.WriteLine()
        For Each item As OrderItem In  order
            Console.WriteLine(item)
        Next item
    End Sub
End Class

' This class represents a simple line item in an order. All the 
' values are immutable except quantity.
' 
Public Class OrderItem
    Public ReadOnly PartNumber As Integer
    Public ReadOnly Description As String
    Public ReadOnly UnitPrice As Double
    
    Private _quantity As Integer = 0
    
    Public Sub New(ByVal partNumber As Integer, _
                   ByVal description As String, _
                   ByVal quantity As Integer, _
                   ByVal unitPrice As Double) 
        Me.PartNumber = partNumber
        Me.Description = description
        Me.Quantity = quantity
        Me.UnitPrice = unitPrice
    End Sub
    
    Public Property Quantity() As Integer 
        Get
            Return _quantity
        End Get
        Set
            If value < 0 Then
                Throw New ArgumentException("Quantity cannot be negative.")
            End If
            _quantity = value
        End Set
    End Property
        
    Public Overrides Function ToString() As String 
        Return String.Format( _
            "{0,9} {1,6} {2,-12} at {3,8:#,###.00} = {4,10:###,###.00}", _
            PartNumber, _quantity, Description, UnitPrice, _
            UnitPrice * _quantity)
    End Function
End Class

' This code example produces the following output:
'
'110072674    400 Widget       at    45.17 =  18,068.00
'110072675     27 Sprocket     at     5.30 =     143.10
'101030411     10 Motor        at   237.50 =   2,375.00
'110072684    175 Gear         at     5.17 =     904.75
'
'Contains(101030411): True
'
'weekly(101030411).Description: Motor
'
'Remove(101030411)
'
'110072674    400 Widget       at    45.17 =  18,068.00
'110072675     27 Sprocket     at     5.30 =     143.10
'110072684    175 Gear         at     5.17 =     904.75
'
'Insert(2, New OrderItem(...))
'
'110072674    400 Widget       at    45.17 =  18,068.00
'110072675     27 Sprocket     at     5.30 =     143.10
'111033401     10 Nut          at      .50 =       5.00
'110072684    175 Gear         at     5.17 =     904.75
'
'coweekly(2).Description: Nut
'
'coweekly(2) = New OrderItem(...)
'
'IndexOf(temp): 2
'
'Remove(temp)
'
'110072674    400 Widget       at    45.17 =  18,068.00
'110072675     27 Sprocket     at     5.30 =     143.10
'110072684    175 Gear         at     5.17 =     904.75
'
'RemoveAt(0)
'
'110072675     27 Sprocket     at     5.30 =     143.10
'110072684    175 Gear         at     5.17 =     904.75

Przykład 2

W poniższym przykładzie kodu pokazano, jak zastąpić chronione InsertItemmetody , , RemoveItemClearItemsi SetItem w celu zapewnienia niestandardowego zachowania dla Addmetod , Removei Clear oraz ustawiania właściwości domyślnej Item[] (indeksator w języku C#). Zachowanie niestandardowe podane w tym przykładzie to zdarzenie powiadomienia o nazwie Changed, które jest wywoływane na końcu każdej z zastąpionych metod.

Przykładowy kod tworzy klasę SimpleOrder pochodzącą z KeyedCollection<TKey,TItem> klasy i reprezentującą prosty formularz zamówienia. Formularz zamówienia zawiera OrderItem obiekty reprezentujące uporządkowane elementy. Przykładowy kod tworzy również klasę zawierającą SimpleOrderChangedEventArgs informacje o zdarzeniu oraz wyliczenie identyfikujące typ zmiany.

W przykładzie kodu pokazano zachowanie niestandardowe przez wywołanie właściwości i metod klasy pochodnej w Main metodzie Demo klasy .

W tym przykładzie kodu są używane obiekty z niezmiennymi kluczami. Aby zapoznać się z przykładem kodu, który używa kluczy modyfikowalnych, zobacz ChangeItemKey.

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

public enum class ChangeTypes
{
    Added,
    Removed, 
    Replaced, 
    Cleared
};

ref class SimpleOrderChangedEventArgs; 

// This class represents a simple line item in an order. All the 
// values are immutable except quantity.
// 
public ref class OrderItem
{
private:
    int _quantity;

public:
    initonly int PartNumber;
    initonly String^ Description;
    initonly double UnitPrice;
        
    OrderItem(int partNumber, String^ description, int quantity, 
        double unitPrice)
    {
        this->PartNumber = partNumber;
        this->Description = description;
        this->Quantity = quantity;
        this->UnitPrice = unitPrice;
    };
    
    property int Quantity    
    {
        int get() { return _quantity; };
        void set(int value)
        {
            if (value < 0)
                throw gcnew ArgumentException("Quantity cannot be negative.");
            
            _quantity = value;
        };
    };
        
    virtual String^ ToString() override 
    {
        return String::Format(
            "{0,9} {1,6} {2,-12} at {3,8:#,###.00} = {4,10:###,###.00}", 
            PartNumber, _quantity, Description, UnitPrice, 
            UnitPrice * _quantity);
    };
};

// Event argument for the Changed event.
//
public ref class SimpleOrderChangedEventArgs : EventArgs
{
public:
    OrderItem^ ChangedItem;
    initonly ChangeTypes ChangeType;
    OrderItem^ ReplacedWith;

    SimpleOrderChangedEventArgs(ChangeTypes change, 
        OrderItem^ item, OrderItem^ replacement)
    {
        this->ChangeType = change;
        this->ChangedItem = item;
        this->ReplacedWith = replacement;
    }
};

// This class derives from KeyedCollection and shows how to override
// the protected ClearItems, InsertItem, RemoveItem, and SetItem 
// methods in order to change the behavior of the default Item 
// property and the Add, Clear, Insert, and Remove methods. The
// class implements a Changed event, which is raised by all the
// protected methods.
//
// SimpleOrder is a collection of OrderItem objects, and its key
// is the PartNumber field of OrderItem-> PartNumber is an Integer,
// so SimpleOrder inherits KeyedCollection<int, OrderItem>.
// (Note that the key of OrderItem cannot be changed; if it could 
// be changed, SimpleOrder would have to override ChangeItemKey.)
//
public ref class SimpleOrder : KeyedCollection<int, OrderItem^>
{
public:
    event EventHandler<SimpleOrderChangedEventArgs^>^ Changed;

    // This parameterless constructor calls the base class constructor
    // that specifies a dictionary threshold of 0, so that the internal
    // dictionary is created as soon as an item is added to the 
    // collection.
    //
    SimpleOrder() : KeyedCollection<int, OrderItem^>(nullptr, 0) {};
    
    // This is the only method that absolutely must be overridden,
    // because without it the KeyedCollection cannot extract the
    // keys from the items. 
    //
protected:
    virtual int GetKeyForItem(OrderItem^ item) override
    {
        // In this example, the key is the part number.
        return item->PartNumber;
    }

    virtual void InsertItem(int index, OrderItem^ newItem) override 
    {
        __super::InsertItem(index, newItem);

        Changed(this, gcnew SimpleOrderChangedEventArgs(
            ChangeTypes::Added, newItem, nullptr));
    }

    virtual void SetItem(int index, OrderItem^ newItem) override 
    {
        OrderItem^ replaced = this->Items[index];
        __super::SetItem(index, newItem);

        Changed(this, gcnew SimpleOrderChangedEventArgs(
            ChangeTypes::Replaced, replaced, newItem));
    }

    virtual void RemoveItem(int index) override 
    {
        OrderItem^ removedItem = Items[index];
        __super::RemoveItem(index);

        Changed(this, gcnew SimpleOrderChangedEventArgs(
            ChangeTypes::Removed, removedItem, nullptr));
    }

    virtual void ClearItems() override 
    {
        __super::ClearItems();

        Changed(this, gcnew SimpleOrderChangedEventArgs(
            ChangeTypes::Cleared, nullptr, nullptr));
    }

    // This method uses the internal reference to the dictionary
    // to test fo
public:
    void AddOrMerge(OrderItem^ newItem)
    {

        int key = this->GetKeyForItem(newItem);
        OrderItem^ existingItem = nullptr;

        // The dictionary is not created until the first item is 
        // added, so it is necessary to test for null. Using 
        // AndAlso ensures that TryGetValue is not called if the
        // dictionary does not exist.
        //
        if (this->Dictionary != nullptr && 
            this->Dictionary->TryGetValue(key, existingItem))
        {
            existingItem->Quantity += newItem->Quantity;
        }
        else
        {
            this->Add(newItem);
        }
    }
};

public ref class Demo
{    
public:
    static void Main()
    {
        SimpleOrder^ weekly = gcnew SimpleOrder();
        weekly->Changed += gcnew 
            EventHandler<SimpleOrderChangedEventArgs^>(ChangedHandler);

        // The Add method, inherited from Collection, takes OrderItem->
        //
        weekly->Add(gcnew OrderItem(110072674, "Widget", 400, 45.17));
        weekly->Add(gcnew OrderItem(110072675, "Sprocket", 27, 5.3));
        weekly->Add(gcnew OrderItem(101030411, "Motor", 10, 237.5));
        weekly->Add(gcnew OrderItem(110072684, "Gear", 175, 5.17));

        Display(weekly);
        
        // The Contains method of KeyedCollection takes TKey.
        //
        Console::WriteLine("\nContains(101030411): {0}", 
            weekly->Contains(101030411));

        // The default Item property of KeyedCollection takes the key
        // type, Integer. The property is read-only.
        //
        Console::WriteLine("\nweekly[101030411]->Description: {0}", 
            weekly[101030411]->Description);

        // The Remove method of KeyedCollection takes a key.
        //
        Console::WriteLine("\nRemove(101030411)");
        weekly->Remove(101030411);

        // The Insert method, inherited from Collection, takes an 
        // index and an OrderItem.
        //
        Console::WriteLine("\nInsert(2, gcnew OrderItem(...))");
        weekly->Insert(2, gcnew OrderItem(111033401, "Nut", 10, .5));
         
        // The default Item property is overloaded. One overload comes
        // from KeyedCollection<int, OrderItem>; that overload
        // is read-only, and takes Integer because it retrieves by key. 
        // The other overload comes from Collection<OrderItem>, the 
        // base class of KeyedCollection<int, OrderItem>; it 
        // retrieves by index, so it also takes an Integer. The compiler
        // uses the most-derived overload, from KeyedCollection, so the
        // only way to access SimpleOrder by index is to cast it to
        // Collection<OrderItem>. Otherwise the index is interpreted
        // as a key, and KeyNotFoundException is thrown.
        //
        Collection<OrderItem^>^ coweekly = weekly;
        Console::WriteLine("\ncoweekly[2].Description: {0}", 
            coweekly[2]->Description);
 
        Console::WriteLine("\ncoweekly[2] = gcnew OrderItem(...)");
        coweekly[2] = gcnew OrderItem(127700026, "Crank", 27, 5.98);

        OrderItem^ temp = coweekly[2];

        // The IndexOf method, inherited from Collection<OrderItem>, 
        // takes an OrderItem instead of a key.
        // 
        Console::WriteLine("\nIndexOf(temp): {0}", weekly->IndexOf(temp));

        // The inherited Remove method also takes an OrderItem->
        //
        Console::WriteLine("\nRemove(temp)");
        weekly->Remove(temp);

        Console::WriteLine("\nRemoveAt(0)");
        weekly->RemoveAt(0);

        weekly->AddOrMerge(gcnew OrderItem(110072684, "Gear", 1000, 5.17));

        Display(weekly);

        Console::WriteLine();
        weekly->Clear();
    }
    
private:
    static void Display(SimpleOrder^ order)
    {
        Console::WriteLine();
        for each( OrderItem^ item in order )
        {
            Console::WriteLine(item);
        }
    }

    static void ChangedHandler(Object^ source, 
        SimpleOrderChangedEventArgs^ e)
    {
        OrderItem^ item = e->ChangedItem;

        if (e->ChangeType == ChangeTypes::Replaced)
        {
            OrderItem^ replacement = e->ReplacedWith;

            Console::WriteLine("{0} (quantity {1}) was replaced " +
                "by {2}, (quantity {3}).", item->Description, 
                item->Quantity, replacement->Description, 
                replacement->Quantity);
        }
        else if(e->ChangeType == ChangeTypes::Cleared)
        {
            Console::WriteLine("The order list was cleared.");
        }
        else
        {
            Console::WriteLine("{0} (quantity {1}) was {2}.", 
                item->Description, item->Quantity, e->ChangeType);
        }
    }
};

void main()
{
    Demo::Main();
}

/* This code example produces the following output:

Widget (quantity 400) was Added.
Sprocket (quantity 27) was Added.
Motor (quantity 10) was Added.
Gear (quantity 175) was Added.

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
101030411     10 Motor        at   237.50 =   2,375.00
110072684    175 Gear         at     5.17 =     904.75

Contains(101030411): True

weekly[101030411]->Description: Motor

Remove(101030411)
Motor (quantity 10) was Removed.

Insert(2, gcnew OrderItem(...))
Nut (quantity 10) was Added.

coweekly[2].Description: Nut

coweekly[2] = gcnew OrderItem(...)
Nut (quantity 10) was replaced by Crank, (quantity 27).

IndexOf(temp): 2

Remove(temp)
Crank (quantity 27) was Removed.

RemoveAt(0)
Widget (quantity 400) was Removed.

110072675     27 Sprocket     at     5.30 =     143.10
110072684   1175 Gear         at     5.17 =   6,074.75

The order list was cleared.
 */
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

// This class derives from KeyedCollection and shows how to override
// the protected ClearItems, InsertItem, RemoveItem, and SetItem
// methods in order to change the behavior of the default Item
// property and the Add, Clear, Insert, and Remove methods. The
// class implements a Changed event, which is raised by all the
// protected methods.
//
// SimpleOrder is a collection of OrderItem objects, and its key
// is the PartNumber field of OrderItem. PartNumber is an Integer,
// so SimpleOrder inherits KeyedCollection<int, OrderItem>.
// (Note that the key of OrderItem cannot be changed; if it could
// be changed, SimpleOrder would have to override ChangeItemKey.)
//
public class SimpleOrder : KeyedCollection<int, OrderItem>
{
    public event EventHandler<SimpleOrderChangedEventArgs> Changed;

    // This parameterless constructor calls the base class constructor
    // that specifies a dictionary threshold of 0, so that the internal
    // dictionary is created as soon as an item is added to the
    // collection.
    //
    public SimpleOrder() : base(null, 0) {}

    // This is the only method that absolutely must be overridden,
    // because without it the KeyedCollection cannot extract the
    // keys from the items.
    //
    protected override int GetKeyForItem(OrderItem item)
    {
        // In this example, the key is the part number.
        return item.PartNumber;
    }

    protected override void InsertItem(int index, OrderItem newItem)
    {
        base.InsertItem(index, newItem);

        EventHandler<SimpleOrderChangedEventArgs> temp = Changed;
        if (temp != null)
        {
            temp(this, new SimpleOrderChangedEventArgs(
                ChangeType.Added, newItem, null));
        }
    }

    protected override void SetItem(int index, OrderItem newItem)
    {
        OrderItem replaced = Items[index];
        base.SetItem(index, newItem);

        EventHandler<SimpleOrderChangedEventArgs> temp = Changed;
        if (temp != null)
        {
            temp(this, new SimpleOrderChangedEventArgs(
                ChangeType.Replaced, replaced, newItem));
        }
    }

    protected override void RemoveItem(int index)
    {
        OrderItem removedItem = Items[index];
        base.RemoveItem(index);

        EventHandler<SimpleOrderChangedEventArgs> temp = Changed;
        if (temp != null)
        {
            temp(this, new SimpleOrderChangedEventArgs(
                ChangeType.Removed, removedItem, null));
        }
    }

    protected override void ClearItems()
    {
        base.ClearItems();

        EventHandler<SimpleOrderChangedEventArgs> temp = Changed;
        if (temp != null)
        {
            temp(this, new SimpleOrderChangedEventArgs(
                ChangeType.Cleared, null, null));
        }
    }
}

// Event argument for the Changed event.
//
public class SimpleOrderChangedEventArgs : EventArgs
{
    private OrderItem _changedItem;
    private ChangeType _changeType;
    private OrderItem _replacedWith;

    public OrderItem ChangedItem { get { return _changedItem; }}
    public ChangeType ChangeType { get { return _changeType; }}
    public OrderItem ReplacedWith { get { return _replacedWith; }}

    public SimpleOrderChangedEventArgs(ChangeType change,
        OrderItem item, OrderItem replacement)
    {
        _changeType = change;
        _changedItem = item;
        _replacedWith = replacement;
    }
}

public enum ChangeType
{
    Added,
    Removed,
    Replaced,
    Cleared
};

public class Demo
{
    public static void Main()
    {
        SimpleOrder weekly = new SimpleOrder();
        weekly.Changed += new
            EventHandler<SimpleOrderChangedEventArgs>(ChangedHandler);

        // The Add method, inherited from Collection, takes OrderItem.
        //
        weekly.Add(new OrderItem(110072674, "Widget", 400, 45.17));
        weekly.Add(new OrderItem(110072675, "Sprocket", 27, 5.3));
        weekly.Add(new OrderItem(101030411, "Motor", 10, 237.5));
        weekly.Add(new OrderItem(110072684, "Gear", 175, 5.17));

        Display(weekly);

        // The Contains method of KeyedCollection takes TKey.
        //
        Console.WriteLine("\nContains(101030411): {0}",
            weekly.Contains(101030411));

        // The default Item property of KeyedCollection takes the key
        // type, Integer. The property is read-only.
        //
        Console.WriteLine("\nweekly[101030411].Description: {0}",
            weekly[101030411].Description);

        // The Remove method of KeyedCollection takes a key.
        //
        Console.WriteLine("\nRemove(101030411)");
        weekly.Remove(101030411);

        // The Insert method, inherited from Collection, takes an
        // index and an OrderItem.
        //
        Console.WriteLine("\nInsert(2, new OrderItem(...))");
        weekly.Insert(2, new OrderItem(111033401, "Nut", 10, .5));

        // The default Item property is overloaded. One overload comes
        // from KeyedCollection<int, OrderItem>; that overload
        // is read-only, and takes Integer because it retrieves by key.
        // The other overload comes from Collection<OrderItem>, the
        // base class of KeyedCollection<int, OrderItem>; it
        // retrieves by index, so it also takes an Integer. The compiler
        // uses the most-derived overload, from KeyedCollection, so the
        // only way to access SimpleOrder by index is to cast it to
        // Collection<OrderItem>. Otherwise the index is interpreted
        // as a key, and KeyNotFoundException is thrown.
        //
        Collection<OrderItem> coweekly = weekly;
        Console.WriteLine("\ncoweekly[2].Description: {0}",
            coweekly[2].Description);

        Console.WriteLine("\ncoweekly[2] = new OrderItem(...)");
        coweekly[2] = new OrderItem(127700026, "Crank", 27, 5.98);

        OrderItem temp = coweekly[2];

        // The IndexOf method, inherited from Collection<OrderItem>,
        // takes an OrderItem instead of a key.
        //
        Console.WriteLine("\nIndexOf(temp): {0}", weekly.IndexOf(temp));

        // The inherited Remove method also takes an OrderItem.
        //
        Console.WriteLine("\nRemove(temp)");
        weekly.Remove(temp);

        Console.WriteLine("\nRemoveAt(0)");
        weekly.RemoveAt(0);

        // Increase the quantity for a line item.
        Console.WriteLine("\ncoweekly(1) = New OrderItem(...)");
        coweekly[1] = new OrderItem(coweekly[1].PartNumber,
            coweekly[1].Description, coweekly[1].Quantity + 1000,
            coweekly[1].UnitPrice);

        Display(weekly);

        Console.WriteLine();
        weekly.Clear();
    }

    private static void Display(SimpleOrder order)
    {
        Console.WriteLine();
        foreach( OrderItem item in order )
        {
            Console.WriteLine(item);
        }
    }

    private static void ChangedHandler(object source,
        SimpleOrderChangedEventArgs e)
    {

        OrderItem item = e.ChangedItem;

        if (e.ChangeType==ChangeType.Replaced)
        {
            OrderItem replacement = e.ReplacedWith;

            Console.WriteLine("{0} (quantity {1}) was replaced " +
                "by {2}, (quantity {3}).", item.Description,
                item.Quantity, replacement.Description,
                replacement.Quantity);
        }
        else if(e.ChangeType == ChangeType.Cleared)
        {
            Console.WriteLine("The order list was cleared.");
        }
        else
        {
            Console.WriteLine("{0} (quantity {1}) was {2}.",
                item.Description, item.Quantity, e.ChangeType);
        }
    }
}

// This class represents a simple line item in an order. All the
// values are immutable except quantity.
//
public class OrderItem
{
    private int _partNumber;
    private string _description;
    private double _unitPrice;
    private int _quantity;

    public int PartNumber { get { return _partNumber; }}
    public string Description { get { return _description; }}
    public double UnitPrice { get { return _unitPrice; }}
    public int Quantity { get { return _quantity; }}

    public OrderItem(int partNumber, string description, int quantity,
        double unitPrice)
    {
        _partNumber = partNumber;
        _description = description;
        _quantity = quantity;
        _unitPrice = unitPrice;
    }

    public override string ToString()
    {
        return String.Format(
            "{0,9} {1,6} {2,-12} at {3,8:#,###.00} = {4,10:###,###.00}",
            PartNumber, _quantity, Description, UnitPrice,
            UnitPrice * _quantity);
    }
}

/* This code example produces the following output:

Widget (quantity 400) was Added.
Sprocket (quantity 27) was Added.
Motor (quantity 10) was Added.
Gear (quantity 175) was Added.

110072674    400 Widget       at    45.17 =  18,068.00
110072675     27 Sprocket     at     5.30 =     143.10
101030411     10 Motor        at   237.50 =   2,375.00
110072684    175 Gear         at     5.17 =     904.75

Contains(101030411): True

weekly[101030411].Description: Motor

Remove(101030411)
Motor (quantity 10) was Removed.

Insert(2, new OrderItem(...))
Nut (quantity 10) was Added.

coweekly[2].Description: Nut

coweekly[2] = new OrderItem(...)
Nut (quantity 10) was replaced by Crank, (quantity 27).

IndexOf(temp): 2

Remove(temp)
Crank (quantity 27) was Removed.

RemoveAt(0)
Widget (quantity 400) was Removed.

coweekly(1) = New OrderItem(...)
Gear (quantity 175) was replaced by Gear, (quantity 1175).

110072675     27 Sprocket     at     5.30 =     143.10
110072684   1175 Gear         at     5.17 =   6,074.75

The order list was cleared.
 */
Imports System.Collections.Generic
Imports System.Collections.ObjectModel

' This class derives from KeyedCollection and shows how to override
' the protected ClearItems, InsertItem, RemoveItem, and SetItem 
' methods in order to change the behavior of the default Item 
' property and the Add, Clear, Insert, and Remove methods. The
' class implements a Changed event, which is raised by all the
' protected methods.
'
' SimpleOrder is a collection of OrderItem objects, and its key
' is the PartNumber field of OrderItem. PartNumber is an Integer,
' so SimpleOrder inherits KeyedCollection(Of Integer, OrderItem).
' (Note that the key of OrderItem cannot be changed; if it could 
' be changed, SimpleOrder would have to override ChangeItemKey.)
'
Public Class SimpleOrder
    Inherits KeyedCollection(Of Integer, OrderItem)

    Public Event Changed As EventHandler(Of SimpleOrderChangedEventArgs)

    ' This parameterless constructor calls the base class constructor
    ' that specifies a dictionary threshold of 0, so that the internal
    ' dictionary is created as soon as an item is added to the 
    ' collection.
    '
    Public Sub New()
        MyBase.New(Nothing, 0)
    End Sub
    
    ' This is the only method that absolutely must be overridden,
    ' because without it the KeyedCollection cannot extract the
    ' keys from the items. 
    '
    Protected Overrides Function GetKeyForItem( _
        ByVal item As OrderItem) As Integer

        ' In this example, the key is the part number.
        Return item.PartNumber   
    End Function

    Protected Overrides Sub InsertItem( _
        ByVal index As Integer, ByVal newItem As OrderItem)

        MyBase.InsertItem(index, newItem)

        RaiseEvent Changed(Me, New SimpleOrderChangedEventArgs( _
            ChangeType.Added, newItem, Nothing))
    End Sub

    Protected Overrides Sub SetItem(ByVal index As Integer, _
        ByVal newItem As OrderItem)

        Dim replaced As OrderItem = Items(index)
        MyBase.SetItem(index, newItem)

        RaiseEvent Changed(Me, New SimpleOrderChangedEventArgs( _
            ChangeType.Replaced, replaced, newItem))
    End Sub

    Protected Overrides Sub RemoveItem(ByVal index As Integer)

        Dim removedItem As OrderItem = Items(index)
        MyBase.RemoveItem(index)

        RaiseEvent Changed(Me, New SimpleOrderChangedEventArgs( _
            ChangeType.Removed, removedItem, Nothing))
    End Sub

    Protected Overrides Sub ClearItems()
        MyBase.ClearItems()

        RaiseEvent Changed(Me, New SimpleOrderChangedEventArgs( _
            ChangeType.Cleared, Nothing, Nothing))
    End Sub

End Class

' Event argument for the Changed event.
'
Public Class SimpleOrderChangedEventArgs
    Inherits EventArgs

    Private _changedItem As OrderItem
    Private _changeType As ChangeType
    Private _replacedWith As OrderItem

    Public ReadOnly Property ChangedItem As OrderItem
        Get
            Return _changedItem
        End Get
    End Property

    Public ReadOnly Property ChangeType As ChangeType
        Get
            Return _changeType
        End Get
    End Property

    Public ReadOnly Property ReplacedWith As OrderItem
        Get
            Return _replacedWith
        End Get
    End Property

    Public Sub New(ByVal change As ChangeType, ByVal item As OrderItem, _
        ByVal replacement As OrderItem)

        _changeType = change
        _changedItem = item
        _replacedWith = replacement
    End Sub
End Class

Public Enum ChangeType
    Added
    Removed
    Replaced
    Cleared
End Enum

Public Class Demo
    
    Public Shared Sub Main() 
        Dim weekly As New SimpleOrder()
        AddHandler weekly.Changed, AddressOf ChangedHandler

        ' The Add method, inherited from Collection, takes OrderItem.
        '
        weekly.Add(New OrderItem(110072674, "Widget", 400, 45.17))
        weekly.Add(New OrderItem(110072675, "Sprocket", 27, 5.3))
        weekly.Add(New OrderItem(101030411, "Motor", 10, 237.5))
        weekly.Add(New OrderItem(110072684, "Gear", 175, 5.17))

        Display(weekly)
        
        ' The Contains method of KeyedCollection takes TKey.
        '
        Console.WriteLine(vbLf & "Contains(101030411): {0}", _
            weekly.Contains(101030411))

        ' The default Item property of KeyedCollection takes the key
        ' type, Integer. The property is read-only.
        '
        Console.WriteLine(vbLf & "weekly(101030411).Description: {0}", _
            weekly(101030411).Description)

        ' The Remove method of KeyedCollection takes a key.
        '
        Console.WriteLine(vbLf & "Remove(101030411)")
        weekly.Remove(101030411)

        ' The Insert method, inherited from Collection, takes an 
        ' index and an OrderItem.
        '
        Console.WriteLine(vbLf & "Insert(2, New OrderItem(...))")
        weekly.Insert(2, New OrderItem(111033401, "Nut", 10, .5))
         
        ' The default Item property is overloaded. One overload comes
        ' from KeyedCollection(Of Integer, OrderItem); that overload
        ' is read-only, and takes Integer because it retrieves by key. 
        ' The other overload comes from Collection(Of OrderItem), the 
        ' base class of KeyedCollection(Of Integer, OrderItem); it 
        ' retrieves by index, so it also takes an Integer. The compiler
        ' uses the most-derived overload, from KeyedCollection, so the
        ' only way to access SimpleOrder by index is to cast it to
        ' Collection(Of OrderItem). Otherwise the index is interpreted
        ' as a key, and KeyNotFoundException is thrown.
        '
        Dim coweekly As Collection(Of OrderItem) = weekly
        Console.WriteLine(vbLf & "coweekly(2).Description: {0}", _
            coweekly(2).Description)
 
        Console.WriteLine(vbLf & "coweekly(2) = New OrderItem(...)")
        coweekly(2) = New OrderItem(127700026, "Crank", 27, 5.98)

        Dim temp As OrderItem = coweekly(2)

        ' The IndexOf method, inherited from Collection(Of OrderItem), 
        ' takes an OrderItem instead of a key.
        ' 
        Console.WriteLine(vbLf & "IndexOf(temp): {0}", _
            weekly.IndexOf(temp))

        ' The inherited Remove method also takes an OrderItem.
        '
        Console.WriteLine(vbLf & "Remove(temp)")
        weekly.Remove(temp)

        Console.WriteLine(vbLf & "RemoveAt(0)")
        weekly.RemoveAt(0)

        ' Increase the quantity for a line item.
        Console.WriteLine(vbLf & "coweekly(1) = New OrderItem(...)")
        coweekly(1) = New OrderItem(coweekly(1).PartNumber, _
            coweekly(1).Description, coweekly(1).Quantity + 1000, _
            coweekly(1).UnitPrice)

        Display(weekly)

        Console.WriteLine()
        weekly.Clear()
    End Sub
    
    Private Shared Sub Display(ByVal order As SimpleOrder) 
        Console.WriteLine()
        For Each item As OrderItem In  order
            Console.WriteLine(item)
        Next item
    End Sub

    Private Shared Sub ChangedHandler(ByVal source As Object, _
        ByVal e As SimpleOrderChangedEventArgs)

        Dim item As OrderItem = e.ChangedItem

        If e.ChangeType = ChangeType.Replaced Then
            Dim replacement As OrderItem = e.ReplacedWith

            Console.WriteLine("{0} (quantity {1}) was replaced " & _
                "by {2}, (quantity {3}).", item.Description, _
                item.Quantity, replacement.Description, replacement.Quantity)

        ElseIf e.ChangeType = ChangeType.Cleared Then
            Console.WriteLine("The order list was cleared.")

        Else
            Console.WriteLine("{0} (quantity {1}) was {2}.", _
                item.Description, item.Quantity, e.ChangeType)
        End If
    End Sub
End Class

' This class represents a simple line item in an order. All the 
' values are immutable except quantity.
' 
Public Class OrderItem
    
    Private _partNumber As Integer
    Private _description As String
    Private _unitPrice As Double
    Private _quantity As Integer

    Public ReadOnly Property PartNumber As Integer
        Get
            Return _partNumber
        End Get
    End Property

    Public ReadOnly Property Description As String
        Get
            Return _description
        End Get
    End Property

    Public ReadOnly Property UnitPrice As Double
        Get
            Return _unitPrice
        End Get
    End Property
    
    Public ReadOnly Property Quantity() As Integer 
        Get
            Return _quantity
        End Get
    End Property
    
    Public Sub New(ByVal partNumber As Integer, _
                   ByVal description As String, _
                   ByVal quantity As Integer, _
                   ByVal unitPrice As Double) 
        _partNumber = partNumber
        _description = description
        _quantity = quantity
        _unitPrice = unitPrice
    End Sub
        
    Public Overrides Function ToString() As String 
        Return String.Format( _
            "{0,9} {1,6} {2,-12} at {3,8:#,###.00} = {4,10:###,###.00}", _
            PartNumber, _quantity, Description, UnitPrice, _
            UnitPrice * _quantity)
    End Function
End Class

' This code example produces the following output:
'
'Widget (quantity 400) was Added.
'Sprocket (quantity 27) was Added.
'Motor (quantity 10) was Added.
'Gear (quantity 175) was Added.
'
'110072674    400 Widget       at    45.17 =  18,068.00
'110072675     27 Sprocket     at     5.30 =     143.10
'101030411     10 Motor        at   237.50 =   2,375.00
'110072684    175 Gear         at     5.17 =     904.75
'
'Contains(101030411): True
'
'weekly(101030411).Description: Motor
'
'Remove(101030411)
'Motor (quantity 10) was Removed.
'
'Insert(2, New OrderItem(...))
'Nut (quantity 10) was Added.
'
'coweekly(2).Description: Nut
'
'coweekly(2) = New OrderItem(...)
'Nut (quantity 10) was replaced by Crank, (quantity 27).
'
'IndexOf(temp): 2
'
'Remove(temp)
'Crank (quantity 27) was Removed.
'
'RemoveAt(0)
'Widget (quantity 400) was Removed.
'
'coweekly(1) = New OrderItem(...)
'Gear (quantity 175) was replaced by Gear, (quantity 1175).
'
'110072675     27 Sprocket     at     5.30 =     143.10
'110072684   1175 Gear         at     5.17 =   6,074.75
'
'The order list was cleared.

Uwagi

Klasa KeyedCollection<TKey,TItem> udostępnia zarówno indeksowane pobieranie O(1), jak i pobieranie kluczy, które zbliża się do metody O(1). Jest to typ abstrakcyjny lub dokładniej nieskończony zestaw typów abstrakcyjnych, ponieważ każdy z ich skonstruowanych typów ogólnych jest abstrakcyjną klasą bazową. Aby użyć klasy KeyedCollection<TKey,TItem>, należy utworzyć typ kolekcji na podstawie odpowiedniego skonstruowanego typu.

Klasa KeyedCollection<TKey,TItem> jest hybrydą między kolekcją opartą na interfejsie IList<T> ogólnym a kolekcją opartą na interfejsie IDictionary<TKey,TValue> ogólnym. Podobnie jak kolekcje oparte na interfejsie IList<T> ogólnym, KeyedCollection<TKey,TItem> jest indeksowaną listą elementów. Podobnie jak kolekcje oparte na interfejsie IDictionary<TKey,TValue> ogólnym, KeyedCollection<TKey,TItem> ma klucz skojarzony z każdym elementem.

W przeciwieństwie do słowników element elementu KeyedCollection<TKey,TItem> nie jest parą klucz/wartość. Zamiast tego cały element jest wartością, a klucz jest osadzony w ramach wartości. Na przykład element kolekcji pochodzącej z KeyedCollection\<String,String> (KeyedCollection(Of String, String) w Visual Basic) może mieć wartość "John Doe Jr.", gdzie wartość to "John Doe Jr"., a klucz to "Doe", lub kolekcja rekordów pracowników zawierających klucze całkowite mogą pochodzić z KeyedCollection\<int,Employee>. Metoda abstrakcyjna GetKeyForItem wyodrębnia klucz z elementu .

Domyślnie element KeyedCollection<TKey,TItem> zawiera słownik odnośników, który można uzyskać za Dictionary pomocą właściwości . Po dodaniu elementu do KeyedCollection<TKey,TItem>elementu klucz elementu jest wyodrębniany raz i zapisywany w słowniku odnośników w celu szybszego wyszukiwania. To zachowanie jest zastępowane przez określenie progu tworzenia słownika podczas tworzenia elementu KeyedCollection<TKey,TItem>. Słownik odnośników jest tworzony po raz pierwszy, gdy liczba elementów przekroczy ten próg. Jeśli określisz wartość -1 jako próg, słownik odnośników nigdy nie zostanie utworzony.

Uwaga

Gdy jest używany wewnętrzny słownik odnośników, zawiera odwołania do wszystkich elementów w kolekcji, jeśli TItem jest typem odwołania, lub kopiami wszystkich elementów w kolekcji, jeśli TItem jest typem wartości. W związku z tym użycie słownika odnośników może nie być odpowiednie, jeśli TItem jest typem wartości.

Dostęp do elementu można uzyskać za pomocą jego indeksu Item[] lub klucza za pomocą właściwości . Możesz dodawać elementy bez klucza, ale dostęp do tych elementów można uzyskać tylko za pomocą indeksu.

Konstruktory

KeyedCollection<TKey,TItem>()

Inicjuje KeyedCollection<TKey,TItem> nowe wystąpienie klasy, które używa domyślnego porównania równości.

KeyedCollection<TKey,TItem>(IEqualityComparer<TKey>)

Inicjuje KeyedCollection<TKey,TItem> nowe wystąpienie klasy, które używa określonego porównania równości.

KeyedCollection<TKey,TItem>(IEqualityComparer<TKey>, Int32)

Inicjuje KeyedCollection<TKey,TItem> nowe wystąpienie klasy, która używa określonego porównania równości i tworzy słownik odnośników po przekroczeniu określonego progu.

Właściwości

Comparer

Pobiera ogólny moduł porównujący równości używany do określania równości kluczy w kolekcji.

Count

Pobiera liczbę elementów faktycznie zawartych w elemecie Collection<T>.

(Odziedziczone po Collection<T>)
Dictionary

Pobiera słownik odnośników obiektu KeyedCollection<TKey,TItem>.

Item[Int32]

Pobiera lub ustawia element pod określonym indeksem.

(Odziedziczone po Collection<T>)
Item[TKey]

Pobiera element z określonym kluczem.

Items

Pobiera otokę IList<T> wokół .Collection<T>

(Odziedziczone po Collection<T>)

Metody

Add(T)

Dodaje obiekt na końcu obiektu Collection<T>.

(Odziedziczone po Collection<T>)
ChangeItemKey(TItem, TKey)

Zmienia klucz skojarzony z określonym elementem w słowniku odnośników.

Clear()

Usuwa wszystkie elementy z obiektu Collection<T>.

(Odziedziczone po Collection<T>)
ClearItems()

Usuwa wszystkie elementy z obiektu KeyedCollection<TKey,TItem>.

Contains(TKey)

Określa, czy kolekcja zawiera element z określonym kluczem.

CopyTo(T[], Int32)

Kopiuje całość Collection<T> do zgodnego jednowymiarowego Arrayobiektu , zaczynając od określonego indeksu tablicy docelowej.

(Odziedziczone po Collection<T>)
Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetEnumerator()

Zwraca moduł wyliczający, który iteruje przez element Collection<T>.

(Odziedziczone po Collection<T>)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetKeyForItem(TItem)

Po zaimplementowaniu w klasie pochodnej wyodrębnia klucz z określonego elementu.

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IndexOf(T)

Wyszukuje określony obiekt i zwraca indeks zerowy pierwszego wystąpienia w całym Collection<T>obiekcie .

(Odziedziczone po Collection<T>)
Insert(Int32, T)

Wstawia element do określonego indeksu Collection<T> .

(Odziedziczone po Collection<T>)
InsertItem(Int32, T)

Wstawia element do określonego indeksu Collection<T> .

(Odziedziczone po Collection<T>)
InsertItem(Int32, TItem)

Wstawia element do określonego indeksu KeyedCollection<TKey,TItem> .

MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
Remove(TKey)

Usuwa element z określonym kluczem z .KeyedCollection<TKey,TItem>

RemoveAt(Int32)

Usuwa element w określonym indeksie obiektu Collection<T>.

(Odziedziczone po Collection<T>)
RemoveItem(Int32)

Usuwa element w określonym indeksie obiektu KeyedCollection<TKey,TItem>.

SetItem(Int32, T)

Zamienia element w określonym indeksie.

(Odziedziczone po Collection<T>)
SetItem(Int32, TItem)

Zamienia element w określonym indeksie na określony element.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)
TryGetValue(TKey, TItem)

Próbuje pobrać element z kolekcji przy użyciu określonego klucza.

Jawne implementacje interfejsu

ICollection.CopyTo(Array, Int32)

Kopiuje elementy ICollection elementu do obiektu Array, zaczynając od określonego Array indeksu.

(Odziedziczone po Collection<T>)
ICollection.IsSynchronized

Pobiera wartość wskazującą, czy dostęp do elementu ICollection jest synchronizowany (bezpieczny wątk).

(Odziedziczone po Collection<T>)
ICollection.SyncRoot

Pobiera obiekt, który może służyć do synchronizowania dostępu do obiektu ICollection.

(Odziedziczone po Collection<T>)
ICollection<T>.IsReadOnly

Pobiera wartość wskazującą, czy kolekcja ICollection<T> jest przeznaczona tylko do odczytu.

(Odziedziczone po Collection<T>)
IEnumerable.GetEnumerator()

Zwraca moduł wyliczający, który iteruje po kolekcji.

(Odziedziczone po Collection<T>)
IList.Add(Object)

Dodaje element do elementu IList.

(Odziedziczone po Collection<T>)
IList.Contains(Object)

Określa, czy element IList zawiera określoną wartość.

(Odziedziczone po Collection<T>)
IList.IndexOf(Object)

Określa indeks określonego elementu w elemencie IList.

(Odziedziczone po Collection<T>)
IList.Insert(Int32, Object)

Wstawia element do IList określonego indeksu.

(Odziedziczone po Collection<T>)
IList.IsFixedSize

Pobiera wartość wskazującą, czy ma IList stały rozmiar.

(Odziedziczone po Collection<T>)
IList.IsReadOnly

Pobiera wartość wskazującą, czy kolekcja IList jest przeznaczona tylko do odczytu.

(Odziedziczone po Collection<T>)
IList.Item[Int32]

Pobiera lub ustawia element pod określonym indeksem.

(Odziedziczone po Collection<T>)
IList.Remove(Object)

Usuwa pierwsze wystąpienie określonego obiektu z obiektu IList.

(Odziedziczone po Collection<T>)

Metody rozszerzania

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

Tworzy obiekt FrozenDictionary<TKey,TValue>IEnumerable<T> na podstawie określonej funkcji selektora kluczy.

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

Tworzy obiekt FrozenDictionary<TKey,TValue>IEnumerable<T> na podstawie określonych funkcji selektora kluczy i selektora elementów.

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

Tworzy obiekt FrozenSet<T> z określonymi wartościami.

AsReadOnly<T>(IList<T>)

Zwraca otokę tylko ReadOnlyCollection<T> do odczytu dla określonej listy.

ToImmutableArray<TSource>(IEnumerable<TSource>)

Tworzy niezmienną tablicę z określonej kolekcji.

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

Tworzy niezmienny słownik z istniejącej kolekcji elementów, stosując funkcję przekształcania do kluczy źródłowych.

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

Tworzy niezmienny słownik na podstawie niektórych przekształceń sekwencji.

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

Wylicza i przekształca sekwencję oraz tworzy niezmienny słownik jego zawartości.

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

Wylicza i przekształca sekwencję oraz tworzy niezmienny słownik jego zawartości przy użyciu określonego modułu porównania kluczy.

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

Wylicza i przekształca sekwencję oraz tworzy niezmienny słownik jego zawartości przy użyciu określonych porównań kluczy i wartości.

ToImmutableHashSet<TSource>(IEnumerable<TSource>)

Wylicza sekwencję i tworzy niezmienny zestaw skrótów jego zawartości.

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

Wylicza sekwencję, tworzy niezmienny zestaw skrótów jego zawartości i używa określonego porównania równości dla typu zestawu.

ToImmutableList<TSource>(IEnumerable<TSource>)

Wylicza sekwencję i tworzy niezmienną listę jej zawartości.

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

Wylicza i przekształca sekwencję oraz tworzy niezmienny posortowany słownik jego zawartości.

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

Wylicza i przekształca sekwencję i tworzy niezmienny posortowany słownik jego zawartości przy użyciu określonego modułu porównania kluczy.

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

Wylicza i przekształca sekwencję oraz tworzy niezmienny posortowany słownik jego zawartości przy użyciu określonych porównań kluczy i wartości.

ToImmutableSortedSet<TSource>(IEnumerable<TSource>)

Wylicza sekwencję i tworzy niezmienialny zestaw posortowany jego zawartości.

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

Wylicza sekwencję, tworzy niezmienialny zestaw posortowany jego zawartości i używa określonego porównania.

CopyToDataTable<T>(IEnumerable<T>)

Zwraca obiekt DataTable zawierający kopie DataRow obiektów, biorąc pod uwagę obiekt wejściowy IEnumerable<T> , w którym parametr T ogólny to DataRow.

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

Kopiuje DataRow obiekty do określonego DataTableobiektu , biorąc pod uwagę obiekt wejściowy IEnumerable<T> , gdzie parametr T ogólny to DataRow.

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

Kopiuje DataRow obiekty do określonego DataTableobiektu , biorąc pod uwagę obiekt wejściowy IEnumerable<T> , gdzie parametr T ogólny to DataRow.

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

Stosuje funkcję akumulatora po sekwencji.

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

Stosuje funkcję akumulatora po sekwencji. Określona wartość inicjatora jest używana jako początkowa wartość akumulatorowa.

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

Stosuje funkcję akumulatora po sekwencji. Określona wartość inicjatora jest używana jako początkowa wartość akumulatorowa, a określona funkcja służy do wybierania wartości wyniku.

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

Udostępnia abstrakcyjną klasę bazową dla kolekcji, której klucze są osadzone w wartościach.

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

Udostępnia abstrakcyjną klasę bazową dla kolekcji, której klucze są osadzone w wartościach.

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

Określa, czy wszystkie elementy sekwencji spełniają warunek.

Any<TSource>(IEnumerable<TSource>)

Określa, czy sekwencja zawiera jakiekolwiek elementy.

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

Określa, czy dowolny element sekwencji spełnia warunek.

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

Dołącza wartość na końcu sekwencji.

AsEnumerable<TSource>(IEnumerable<TSource>)

Zwraca dane wejściowe wpisane jako IEnumerable<T>.

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

Oblicza średnią sekwencji Decimal wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza średnią sekwencji Double wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza średnią sekwencji Int32 wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza średnią sekwencji Int64 wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza średnią sekwencji wartości dopuszczających Decimal wartość null, które są uzyskiwane przez wywołanie funkcji transform na każdym elemecie sekwencji danych wejściowych.

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

Oblicza średnią sekwencji wartości dopuszczających Double wartość null, które są uzyskiwane przez wywołanie funkcji transform na każdym elemecie sekwencji danych wejściowych.

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

Oblicza średnią sekwencji wartości dopuszczających Int32 wartość null, które są uzyskiwane przez wywołanie funkcji transform na każdym elemecie sekwencji danych wejściowych.

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

Oblicza średnią sekwencji wartości dopuszczających Int64 wartość null, które są uzyskiwane przez wywołanie funkcji transform na każdym elemecie sekwencji danych wejściowych.

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

Oblicza średnią sekwencji wartości dopuszczających Single wartość null, które są uzyskiwane przez wywołanie funkcji transform na każdym elemecie sekwencji danych wejściowych.

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

Oblicza średnią sekwencji Single wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

Cast<TResult>(IEnumerable)

Rzutuje elementy obiektu IEnumerable na określony typ.

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

Dzieli elementy sekwencji na fragmenty o rozmiarze najwyżej size.

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

Łączy dwie sekwencje.

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

Określa, czy sekwencja zawiera określony element przy użyciu domyślnego modułu porównania równości.

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

Określa, czy sekwencja zawiera określony element przy użyciu określonego IEqualityComparer<T>elementu .

Count<TSource>(IEnumerable<TSource>)

Zwraca liczbę elementów w sekwencji.

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

Zwraca liczbę reprezentującą, ile elementów w określonej sekwencji spełnia warunek.

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

Udostępnia abstrakcyjną klasę bazową dla kolekcji, której klucze są osadzone w wartościach.

DefaultIfEmpty<TSource>(IEnumerable<TSource>)

Zwraca elementy określonej sekwencji lub wartość domyślną parametru typu w kolekcji pojedynczej, jeśli sekwencja jest pusta.

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

Zwraca elementy określonej sekwencji lub określoną wartość w kolekcji pojedynczej, jeśli sekwencja jest pusta.

Distinct<TSource>(IEnumerable<TSource>)

Zwraca różne elementy z sekwencji przy użyciu domyślnego modułu porównującego równości do porównywania wartości.

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

Zwraca różne elementy z sekwencji przy użyciu określonej IEqualityComparer<T> wartości w celu porównania wartości.

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

Zwraca różne elementy z sekwencji zgodnie z określoną funkcją selektora kluczy.

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

Zwraca różne elementy z sekwencji zgodnie z określoną funkcją selektora kluczy i przy użyciu określonego modułu porównującego do porównywania kluczy.

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

Zwraca element w określonym indeksie w sekwencji.

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

Zwraca element w określonym indeksie w sekwencji.

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

Zwraca element w określonym indeksie w sekwencji lub wartość domyślną, jeśli indeks jest poza zakresem.

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

Zwraca element w określonym indeksie w sekwencji lub wartość domyślną, jeśli indeks jest poza zakresem.

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

Tworzy różnicę zestawu dwóch sekwencji przy użyciu domyślnego porównania równości do porównywania wartości.

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

Tworzy różnicę zestawu dwóch sekwencji przy użyciu określonego IEqualityComparer<T> do porównywania wartości.

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

Tworzy różnicę zestawu dwóch sekwencji zgodnie z określoną funkcją selektora kluczy.

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

Tworzy różnicę zestawu dwóch sekwencji zgodnie z określoną funkcją selektora kluczy.

First<TSource>(IEnumerable<TSource>)

Zwraca pierwszy element sekwencji.

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

Zwraca pierwszy element w sekwencji, który spełnia określony warunek.

FirstOrDefault<TSource>(IEnumerable<TSource>)

Zwraca pierwszy element sekwencji lub wartość domyślną, jeśli sekwencja nie zawiera żadnych elementów.

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

Zwraca pierwszy element sekwencji lub określoną wartość domyślną, jeśli sekwencja nie zawiera żadnych elementów.

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

Zwraca pierwszy element sekwencji, który spełnia warunek lub wartość domyślną, jeśli taki element nie zostanie znaleziony.

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

Zwraca pierwszy element sekwencji, który spełnia warunek lub określoną wartość domyślną, jeśli taki element nie zostanie znaleziony.

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

Grupuje elementy sekwencji zgodnie z określoną funkcją selektora kluczy.

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

Grupuje elementy sekwencji zgodnie z określoną funkcją selektora kluczy i porównuje klucze przy użyciu określonego modułu porównującego.

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

Grupuje elementy sekwencji zgodnie z określoną funkcją selektora kluczy i projektuje elementy dla każdej grupy przy użyciu określonej funkcji.

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

Grupuje elementy sekwencji zgodnie z funkcją selektora klucza. Klucze są porównywane przy użyciu modułu porównującego, a elementy każdej grupy są rzutowane przy użyciu określonej funkcji.

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

Grupuje elementy sekwencji zgodnie z określoną kluczową funkcją wyboru i tworzy wartość wyniku z każdej grupy i klucza.

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

Grupuje elementy sekwencji zgodnie z określoną kluczową funkcją wyboru i tworzy wartość wyniku z każdej grupy i klucza. Klucze są porównywane przy użyciu określonego modułu porównującego.

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

Grupuje elementy sekwencji zgodnie z określoną kluczową funkcją wyboru i tworzy wartość wyniku z każdej grupy i klucza. Elementy każdej grupy są rzutowane przy użyciu określonej funkcji.

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

Grupuje elementy sekwencji zgodnie z określoną kluczową funkcją wyboru i tworzy wartość wyniku z każdej grupy i klucza. Wartości klucza są porównywane przy użyciu określonego modułu porównującego, a elementy każdej grupy są rzutowane przy użyciu określonej funkcji.

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

Koreluje elementy dwóch sekwencji na podstawie równości kluczy i grupuje wyniki. Domyślny moduł porównujący równości służy do porównywania kluczy.

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

Koreluje elementy dwóch sekwencji na podstawie równości klucza i grupuje wyniki. Określony IEqualityComparer<T> element służy do porównywania kluczy.

Index<TSource>(IEnumerable<TSource>)

Udostępnia abstrakcyjną klasę bazową dla kolekcji, której klucze są osadzone w wartościach.

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

Tworzy część wspólną zestawu dwóch sekwencji przy użyciu domyślnego modułu porównania równości do porównywania wartości.

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

Tworzy część wspólną zestawu dwóch sekwencji, używając określonej IEqualityComparer<T> wartości do porównania wartości.

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

Tworzy część wspólną zestawu dwóch sekwencji zgodnie z określoną funkcją selektora kluczy.

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

Tworzy część wspólną zestawu dwóch sekwencji zgodnie z określoną funkcją selektora kluczy.

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

Koreluje elementy dwóch sekwencji na podstawie pasujących kluczy. Domyślny moduł porównujący równości służy do porównywania kluczy.

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

Koreluje elementy dwóch sekwencji na podstawie pasujących kluczy. Określony IEqualityComparer<T> element służy do porównywania kluczy.

Last<TSource>(IEnumerable<TSource>)

Zwraca ostatni element sekwencji.

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

Zwraca ostatni element sekwencji, który spełnia określony warunek.

LastOrDefault<TSource>(IEnumerable<TSource>)

Zwraca ostatni element sekwencji lub wartość domyślną, jeśli sekwencja nie zawiera żadnych elementów.

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

Zwraca ostatni element sekwencji lub określoną wartość domyślną, jeśli sekwencja nie zawiera żadnych elementów.

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

Zwraca ostatni element sekwencji, który spełnia warunek lub wartość domyślną, jeśli taki element nie zostanie znaleziony.

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

Zwraca ostatni element sekwencji, który spełnia warunek lub określoną wartość domyślną, jeśli taki element nie zostanie znaleziony.

LongCount<TSource>(IEnumerable<TSource>)

Zwraca wartość , Int64 która reprezentuje łączną liczbę elementów w sekwencji.

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

Zwraca wartość Int64 , która reprezentuje, ile elementów w sekwencji spełnia warunek.

Max<TSource>(IEnumerable<TSource>)

Zwraca wartość maksymalną w sekwencji ogólnej.

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

Zwraca wartość maksymalną w sekwencji ogólnej.

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

Wywołuje funkcję transform dla każdego elementu sekwencji i zwraca maksymalną Decimal wartość.

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

Wywołuje funkcję transform dla każdego elementu sekwencji i zwraca maksymalną Double wartość.

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

Wywołuje funkcję transform dla każdego elementu sekwencji i zwraca maksymalną Int32 wartość.

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

Wywołuje funkcję transform dla każdego elementu sekwencji i zwraca maksymalną Int64 wartość.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca maksymalną wartość dopuszczaną Decimal do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca maksymalną wartość dopuszczaną Double do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca maksymalną wartość dopuszczaną Int32 do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca maksymalną wartość dopuszczaną Int64 do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca maksymalną wartość dopuszczaną Single do wartości null.

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

Wywołuje funkcję transform dla każdego elementu sekwencji i zwraca maksymalną Single wartość.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji ogólnej i zwraca maksymalną wartość wynikową.

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

Zwraca wartość maksymalną w sekwencji ogólnej zgodnie z określoną funkcją selektora kluczy.

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

Zwraca wartość maksymalną w sekwencji ogólnej zgodnie z określoną funkcją selektora kluczy i modułem porównującym klucz.

Min<TSource>(IEnumerable<TSource>)

Zwraca wartość minimalną w sekwencji ogólnej.

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

Zwraca wartość minimalną w sekwencji ogólnej.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca wartość minimalną Decimal .

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca wartość minimalną Double .

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca wartość minimalną Int32 .

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca wartość minimalną Int64 .

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca minimalną wartość dopuszczaną Decimal do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca minimalną wartość dopuszczaną Double do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca minimalną wartość dopuszczaną Int32 do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca minimalną wartość dopuszczaną Int64 do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca minimalną wartość dopuszczaną Single do wartości null.

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji i zwraca wartość minimalną Single .

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

Wywołuje funkcję przekształcania dla każdego elementu sekwencji ogólnej i zwraca minimalną wartość wynikową.

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

Zwraca wartość minimalną w sekwencji ogólnej zgodnie z określoną funkcją selektora kluczy.

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

Zwraca wartość minimalną w sekwencji ogólnej zgodnie z określoną funkcją selektora kluczy i modułem porównującym klucz.

OfType<TResult>(IEnumerable)

Filtruje elementy IEnumerable elementu na podstawie określonego typu.

Order<T>(IEnumerable<T>)

Sortuje elementy sekwencji w kolejności rosnącej.

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

Sortuje elementy sekwencji w kolejności rosnącej.

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

Sortuje elementy sekwencji w kolejności rosnącej zgodnie z kluczem.

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

Sortuje elementy sekwencji w kolejności rosnącej przy użyciu określonego modułu porównującego.

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

Sortuje elementy sekwencji w kolejności malejącej zgodnie z kluczem.

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

Sortuje elementy sekwencji w kolejności malejącej przy użyciu określonego modułu porównującego.

OrderDescending<T>(IEnumerable<T>)

Sortuje elementy sekwencji w kolejności malejącej.

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

Sortuje elementy sekwencji w kolejności malejącej.

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

Dodaje wartość na początku sekwencji.

Reverse<TSource>(IEnumerable<TSource>)

Odwraca kolejność elementów w sekwencji.

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

Projektuje każdy element sekwencji w nowym formularzu.

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

Projektuje każdy element sekwencji w nowym formularzu przez dołączenie indeksu elementu.

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

Projektuje każdy element sekwencji i IEnumerable<T> spłaszcza wynikowe sekwencje w jedną sekwencję.

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

Projektuje każdy element sekwencji do IEnumerable<T>obiektu i spłaszcza wynikowe sekwencje w jedną sekwencję. Indeks każdego elementu źródłowego jest używany w przewidywanej formie tego elementu.

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

Projektuje każdy element sekwencji do IEnumerable<T>obiektu , spłaszcza wynikowe sekwencje w jedną sekwencję i wywołuje funkcję selektora wyników w każdym z nich.

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

Projektuje każdy element sekwencji do IEnumerable<T>obiektu , spłaszcza wynikowe sekwencje w jedną sekwencję i wywołuje funkcję selektora wyników w każdym z nich. Indeks każdego elementu źródłowego jest używany w pośredniej przewidywanej formie tego elementu.

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

Określa, czy dwie sekwencje są równe, porównując elementy przy użyciu domyślnego porównania równości dla ich typu.

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

Określa, czy dwie sekwencje są równe, porównując ich elementy przy użyciu określonego IEqualityComparer<T>elementu .

Single<TSource>(IEnumerable<TSource>)

Zwraca jedyny element sekwencji i zgłasza wyjątek, jeśli nie ma dokładnie jednego elementu w sekwencji.

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

Zwraca jedyny element sekwencji, który spełnia określony warunek, i zgłasza wyjątek, jeśli istnieje więcej niż jeden taki element.

SingleOrDefault<TSource>(IEnumerable<TSource>)

Zwraca jedyny element sekwencji lub wartość domyślną, jeśli sekwencja jest pusta; Ta metoda zgłasza wyjątek, jeśli sekwencja zawiera więcej niż jeden element.

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

Zwraca jedyny element sekwencji lub określoną wartość domyślną, jeśli sekwencja jest pusta; Ta metoda zgłasza wyjątek, jeśli sekwencja zawiera więcej niż jeden element.

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

Zwraca jedyny element sekwencji, który spełnia określony warunek lub wartość domyślną, jeśli taki element nie istnieje; Ta metoda zgłasza wyjątek, jeśli warunek spełnia więcej niż jeden element.

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

Zwraca jedyny element sekwencji, który spełnia określony warunek lub określoną wartość domyślną, jeśli taki element nie istnieje; Ta metoda zgłasza wyjątek, jeśli warunek spełnia więcej niż jeden element.

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

Pomija określoną liczbę elementów w sekwencji, a następnie zwraca pozostałe elementy.

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

Zwraca nową kolekcję wyliczalną zawierającą elementy z source ostatnich count elementów kolekcji źródłowej pominiętą.

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

Pomija elementy w sekwencji, o ile określony warunek jest spełniony, a następnie zwraca pozostałe elementy.

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

Pomija elementy w sekwencji, o ile określony warunek jest spełniony, a następnie zwraca pozostałe elementy. Indeks elementu jest używany w logice funkcji predykatu.

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

Oblicza sumę sekwencji Decimal wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji Double wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji Int32 wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji Int64 wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji wartości dopuszczających wartość null, które są uzyskiwane Decimal przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji wartości dopuszczających wartość null, które są uzyskiwane Double przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji wartości dopuszczających wartość null, które są uzyskiwane Int32 przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji wartości dopuszczających wartość null, które są uzyskiwane Int64 przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji wartości dopuszczających wartość null, które są uzyskiwane Single przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Oblicza sumę sekwencji Single wartości uzyskanych przez wywołanie funkcji przekształcania dla każdego elementu sekwencji danych wejściowych.

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

Zwraca określoną liczbę ciągłych elementów od początku sekwencji.

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

Zwraca określony zakres ciągłych elementów z sekwencji.

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

Zwraca nową kolekcję wyliczalną zawierającą ostatnie count elementy z klasy source.

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

Zwraca elementy z sekwencji, o ile określony warunek ma wartość true.

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

Zwraca elementy z sekwencji, o ile określony warunek ma wartość true. Indeks elementu jest używany w logice funkcji predykatu.

ToArray<TSource>(IEnumerable<TSource>)

Tworzy tablicę na podstawie elementu IEnumerable<T>.

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

Tworzy obiekt Dictionary<TKey,TValue> na podstawie IEnumerable<T> określonej funkcji selektora klucza.

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

Tworzy element Dictionary<TKey,TValue>IEnumerable<T> na podstawie określonej funkcji selektora kluczy i modułu porównania kluczy.

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

Tworzy obiekt Dictionary<TKey,TValue>IEnumerable<T> na podstawie określonych funkcji selektora kluczy i selektora elementów.

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

Tworzy element Dictionary<TKey,TValue> na podstawie IEnumerable<T> określonej funkcji selektora kluczy, modułu porównującego i funkcji selektora elementów.

ToHashSet<TSource>(IEnumerable<TSource>)

Tworzy obiekt na HashSet<T> podstawie elementu IEnumerable<T>.

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

Tworzy obiekt HashSet<T>IEnumerable<T> na podstawie elementu comparer , aby porównać klucze.

ToList<TSource>(IEnumerable<TSource>)

Tworzy obiekt na List<T> podstawie elementu IEnumerable<T>.

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

Tworzy obiekt Lookup<TKey,TElement> na podstawie IEnumerable<T> określonej funkcji selektora klucza.

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

Tworzy element Lookup<TKey,TElement>IEnumerable<T> na podstawie określonej funkcji selektora kluczy i modułu porównania kluczy.

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

Tworzy obiekt Lookup<TKey,TElement>IEnumerable<T> na podstawie określonych funkcji selektora kluczy i selektora elementów.

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

Tworzy element Lookup<TKey,TElement> na podstawie IEnumerable<T> określonej funkcji selektora kluczy, modułu porównującego i funkcji selektora elementów.

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

Próbuje określić liczbę elementów w sekwencji bez wymuszania wyliczenia.

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

Tworzy połączenie zestawu dwóch sekwencji przy użyciu domyślnego porównania równości.

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

Tworzy zestaw unii dwóch sekwencji przy użyciu określonego IEqualityComparer<T>.

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

Tworzy połączenie zestawu dwóch sekwencji zgodnie z określoną funkcją selektora kluczy.

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

Tworzy połączenie zestawu dwóch sekwencji zgodnie z określoną funkcją selektora kluczy.

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

Filtruje sekwencję wartości na podstawie predykatu.

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

Filtruje sekwencję wartości na podstawie predykatu. Indeks każdego elementu jest używany w logice funkcji predykatu.

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

Tworzy sekwencję krotki z elementami z dwóch określonych sekwencji.

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

Tworzy sekwencję krotki z elementami z trzech określonych sekwencji.

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

Stosuje określoną funkcję do odpowiednich elementów dwóch sekwencji, tworząc sekwencję wyników.

AsParallel(IEnumerable)

Umożliwia równoległość zapytania.

AsParallel<TSource>(IEnumerable<TSource>)

Umożliwia równoległość zapytania.

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

AsQueryable<TElement>(IEnumerable<TElement>)

Konwertuje rodzajowy IEnumerable<T> na ogólny IQueryable<T>.

Ancestors<T>(IEnumerable<T>)

Zwraca kolekcję elementów, które zawierają elementy podrzędne każdego węzła w kolekcji źródłowej.

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

Zwraca przefiltrowaną kolekcję elementów, które zawierają elementy będące elementami głównymi każdego węzła w kolekcji źródłowej. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

DescendantNodes<T>(IEnumerable<T>)

Zwraca kolekcję węzłów podrzędnych każdego dokumentu i elementu w kolekcji źródłowej.

Descendants<T>(IEnumerable<T>)

Zwraca kolekcję elementów, które zawierają elementy podrzędne każdego elementu i dokumentu w kolekcji źródłowej.

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

Zwraca filtrowaną kolekcję elementów, które zawierają elementy podrzędne każdego elementu i dokumentu w kolekcji źródłowej. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

Elements<T>(IEnumerable<T>)

Zwraca kolekcję elementów podrzędnych każdego elementu i dokumentu w kolekcji źródłowej.

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

Zwraca filtrowaną kolekcję elementów podrzędnych każdego elementu i dokumentu w kolekcji źródłowej. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

InDocumentOrder<T>(IEnumerable<T>)

Zwraca kolekcję węzłów zawierającą wszystkie węzły w kolekcji źródłowej posortowane w kolejności dokumentu.

Nodes<T>(IEnumerable<T>)

Zwraca kolekcję węzłów podrzędnych każdego dokumentu i elementu w kolekcji źródłowej.

Remove<T>(IEnumerable<T>)

Usuwa każdy węzeł w kolekcji źródłowej z węzła nadrzędnego.

Dotyczy

Zobacz też