LinkedList<T> 类

定义

表示双重链接列表。

generic <typename T>
public ref class LinkedList : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::ICollection
generic <typename T>
public ref class LinkedList : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::ICollection, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class LinkedList : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::ICollection, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class LinkedList : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::ICollection
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.ICollection
type LinkedList<'T> = class
    interface ICollection<'T>
    interface seq<'T>
    interface IEnumerable
    interface IReadOnlyCollection<'T>
    interface ICollection
type LinkedList<'T> = class
    interface ICollection<'T>
    interface seq<'T>
    interface IEnumerable
    interface IReadOnlyCollection<'T>
    interface ICollection
    interface IDeserializationCallback
    interface ISerializable
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type LinkedList<'T> = class
    interface ICollection<'T>
    interface seq<'T>
    interface ICollection
    interface IEnumerable
    interface ISerializable
    interface IDeserializationCallback
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type LinkedList<'T> = class
    interface ICollection<'T>
    interface seq<'T>
    interface IEnumerable
    interface ICollection
    interface IReadOnlyCollection<'T>
    interface ISerializable
    interface IDeserializationCallback
type LinkedList<'T> = class
    interface ICollection<'T>
    interface seq<'T>
    interface ICollection
    interface IEnumerable
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IEnumerable(Of T), IReadOnlyCollection(Of T)
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), IReadOnlyCollection(Of T), ISerializable
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), ISerializable
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IEnumerable(Of T)

类型参数

T

指定链接列表的元素类型。

继承
LinkedList<T>
属性
实现

示例

下面的代码示例演示 类的许多 LinkedList<T> 功能。

#using <System.dll>

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

public ref class Example
{
public:
    static void Main()
    {
        // Create the link list.
        array<String^>^ words =
            { "the", "fox", "jumped", "over", "the", "dog" };
        LinkedList<String^>^ sentence = gcnew LinkedList<String^>(words);
        Display(sentence, "The linked list values:");
        Console::WriteLine("sentence.Contains(\"jumped\") = {0}",
            sentence->Contains("jumped"));

        // Add the word 'today' to the beginning of the linked list.
        sentence->AddFirst("today");
        Display(sentence, "Test 1: Add 'today' to beginning of the list:");

        // Move the first node to be the last node.
        LinkedListNode<String^>^ mark1 = sentence->First;
        sentence->RemoveFirst();
        sentence->AddLast(mark1);
        Display(sentence, "Test 2: Move first node to be last node:");

        // Change the last node to 'yesterday'.
        sentence->RemoveLast();
        sentence->AddLast("yesterday");
        Display(sentence, "Test 3: Change the last node to 'yesterday':");

        // Move the last node to be the first node.
        mark1 = sentence->Last;
        sentence->RemoveLast();
        sentence->AddFirst(mark1);
        Display(sentence, "Test 4: Move last node to be first node:");


        // Indicate the last occurence of 'the'.
        sentence->RemoveFirst();
        LinkedListNode<String^>^ current = sentence->FindLast("the");
        IndicateNode(current, "Test 5: Indicate last occurence of 'the':");

        // Add 'lazy' and 'old' after 'the' (the LinkedListNode named current).
        sentence->AddAfter(current, "old");
        sentence->AddAfter(current, "lazy");
        IndicateNode(current, "Test 6: Add 'lazy' and 'old' after 'the':");

        // Indicate 'fox' node.
        current = sentence->Find("fox");
        IndicateNode(current, "Test 7: Indicate the 'fox' node:");

        // Add 'quick' and 'brown' before 'fox':
        sentence->AddBefore(current, "quick");
        sentence->AddBefore(current, "brown");
        IndicateNode(current, "Test 8: Add 'quick' and 'brown' before 'fox':");

        // Keep a reference to the current node, 'fox',
        // and to the previous node in the list. Indicate the 'dog' node.
        mark1 = current;
        LinkedListNode<String^>^ mark2 = current->Previous;
        current = sentence->Find("dog");
        IndicateNode(current, "Test 9: Indicate the 'dog' node:");

        // The AddBefore method throws an InvalidOperationException
        // if you try to add a node that already belongs to a list.
        Console::WriteLine("Test 10: Throw exception by adding node (fox) already in the list:");
        try
        {
            sentence->AddBefore(current, mark1);
        }
        catch (InvalidOperationException^ ex)
        {
            Console::WriteLine("Exception message: {0}", ex->Message);
        }
        Console::WriteLine();

        // Remove the node referred to by mark1, and then add it
        // before the node referred to by current.
        // Indicate the node referred to by current.
        sentence->Remove(mark1);
        sentence->AddBefore(current, mark1);
        IndicateNode(current, "Test 11: Move a referenced node (fox) before the current node (dog):");

        // Remove the node referred to by current.
        sentence->Remove(current);
        IndicateNode(current, "Test 12: Remove current node (dog) and attempt to indicate it:");

        // Add the node after the node referred to by mark2.
        sentence->AddAfter(mark2, current);
        IndicateNode(current, "Test 13: Add node removed in test 11 after a referenced node (brown):");

        // The Remove method finds and removes the
        // first node that that has the specified value.
        sentence->Remove("old");
        Display(sentence, "Test 14: Remove node that has the value 'old':");

        // When the linked list is cast to ICollection(Of String),
        // the Add method adds a node to the end of the list.
        sentence->RemoveLast();
        ICollection<String^>^ icoll = sentence;
        icoll->Add("rhinoceros");
        Display(sentence, "Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':");

        Console::WriteLine("Test 16: Copy the list to an array:");
        // Create an array with the same number of
        // elements as the inked list.
        array<String^>^ sArray = gcnew array<String^>(sentence->Count);
        sentence->CopyTo(sArray, 0);

        for each (String^ s in sArray)
        {
            Console::WriteLine(s);
        }


        // Release all the nodes.
        sentence->Clear();

        Console::WriteLine();
        Console::WriteLine("Test 17: Clear linked list. Contains 'jumped' = {0}",
            sentence->Contains("jumped"));

        Console::ReadLine();
    }

private:
    static void Display(LinkedList<String^>^ words, String^ test)
    {
        Console::WriteLine(test);
        for each (String^ word in words)
        {
            Console::Write(word + " ");
        }
        Console::WriteLine();
        Console::WriteLine();
    }

    static void IndicateNode(LinkedListNode<String^>^ node, String^ test)
    {
        Console::WriteLine(test);
        if (node->List == nullptr)
        {
            Console::WriteLine("Node '{0}' is not in the list.\n",
                node->Value);
            return;
        }

        StringBuilder^ result = gcnew StringBuilder("(" + node->Value + ")");
        LinkedListNode<String^>^ nodeP = node->Previous;

        while (nodeP != nullptr)
        {
            result->Insert(0, nodeP->Value + " ");
            nodeP = nodeP->Previous;
        }

        node = node->Next;
        while (node != nullptr)
        {
            result->Append(" " + node->Value);
            node = node->Next;
        }

        Console::WriteLine(result);
        Console::WriteLine();
    }
};

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

//This code example produces the following output:
//
//The linked list values:
//the fox jumped over the dog

//Test 1: Add 'today' to beginning of the list:
//today the fox jumped over the dog

//Test 2: Move first node to be last node:
//the fox jumped over the dog today

//Test 3: Change the last node to 'yesterday':
//the fox jumped over the dog yesterday

//Test 4: Move last node to be first node:
//yesterday the fox jumped over the dog

//Test 5: Indicate last occurence of 'the':
//the fox jumped over (the) dog

//Test 6: Add 'lazy' and 'old' after 'the':
//the fox jumped over (the) lazy old dog

//Test 7: Indicate the 'fox' node:
//the (fox) jumped over the lazy old dog

//Test 8: Add 'quick' and 'brown' before 'fox':
//the quick brown (fox) jumped over the lazy old dog

//Test 9: Indicate the 'dog' node:
//the quick brown fox jumped over the lazy old (dog)

//Test 10: Throw exception by adding node (fox) already in the list:
//Exception message: The LinkedList node belongs a LinkedList.

//Test 11: Move a referenced node (fox) before the current node (dog):
//the quick brown jumped over the lazy old fox (dog)

//Test 12: Remove current node (dog) and attempt to indicate it:
//Node 'dog' is not in the list.

//Test 13: Add node removed in test 11 after a referenced node (brown):
//the quick brown (dog) jumped over the lazy old fox

//Test 14: Remove node that has the value 'old':
//the quick brown dog jumped over the lazy fox

//Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':
//the quick brown dog jumped over the lazy rhinoceros

//Test 16: Copy the list to an array:
//the
//quick
//brown
//dog
//jumped
//over
//the
//lazy
//rhinoceros

//Test 17: Clear linked list. Contains 'jumped' = False
//
using System;
using System.Text;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        // Create the link list.
        string[] words =
            { "the", "fox", "jumps", "over", "the", "dog" };
        LinkedList<string> sentence = new LinkedList<string>(words);
        Display(sentence, "The linked list values:");

        // Add the word 'today' to the beginning of the linked list.
        sentence.AddFirst("today");
        Display(sentence, "Test 1: Add 'today' to beginning of the list:");

        // Move the first node to be the last node.
        LinkedListNode<string> mark1 = sentence.First;
        sentence.RemoveFirst();
        sentence.AddLast(mark1);
        Display(sentence, "Test 2: Move first node to be last node:");

        // Change the last node to 'yesterday'.
        sentence.RemoveLast();
        sentence.AddLast("yesterday");
        Display(sentence, "Test 3: Change the last node to 'yesterday':");

        // Move the last node to be the first node.
        mark1 = sentence.Last;
        sentence.RemoveLast();
        sentence.AddFirst(mark1);
        Display(sentence, "Test 4: Move last node to be first node:");

        // Indicate the last occurence of 'the'.
        sentence.RemoveFirst();
        LinkedListNode<string> current = sentence.FindLast("the");
        IndicateNode(current, "Test 5: Indicate last occurence of 'the':");

        // Add 'lazy' and 'old' after 'the' (the LinkedListNode named current).
        sentence.AddAfter(current, "old");
        sentence.AddAfter(current, "lazy");
        IndicateNode(current, "Test 6: Add 'lazy' and 'old' after 'the':");

        // Indicate 'fox' node.
        current = sentence.Find("fox");
        IndicateNode(current, "Test 7: Indicate the 'fox' node:");

        // Add 'quick' and 'brown' before 'fox':
        sentence.AddBefore(current, "quick");
        sentence.AddBefore(current, "brown");
        IndicateNode(current, "Test 8: Add 'quick' and 'brown' before 'fox':");

        // Keep a reference to the current node, 'fox',
        // and to the previous node in the list. Indicate the 'dog' node.
        mark1 = current;
        LinkedListNode<string> mark2 = current.Previous;
        current = sentence.Find("dog");
        IndicateNode(current, "Test 9: Indicate the 'dog' node:");

        // The AddBefore method throws an InvalidOperationException
        // if you try to add a node that already belongs to a list.
        Console.WriteLine("Test 10: Throw exception by adding node (fox) already in the list:");
        try
        {
            sentence.AddBefore(current, mark1);
        }
        catch (InvalidOperationException ex)
        {
            Console.WriteLine("Exception message: {0}", ex.Message);
        }
        Console.WriteLine();

        // Remove the node referred to by mark1, and then add it
        // before the node referred to by current.
        // Indicate the node referred to by current.
        sentence.Remove(mark1);
        sentence.AddBefore(current, mark1);
        IndicateNode(current, "Test 11: Move a referenced node (fox) before the current node (dog):");

        // Remove the node referred to by current.
        sentence.Remove(current);
        IndicateNode(current, "Test 12: Remove current node (dog) and attempt to indicate it:");

        // Add the node after the node referred to by mark2.
        sentence.AddAfter(mark2, current);
        IndicateNode(current, "Test 13: Add node removed in test 11 after a referenced node (brown):");

        // The Remove method finds and removes the
        // first node that that has the specified value.
        sentence.Remove("old");
        Display(sentence, "Test 14: Remove node that has the value 'old':");

        // When the linked list is cast to ICollection(Of String),
        // the Add method adds a node to the end of the list.
        sentence.RemoveLast();
        ICollection<string> icoll = sentence;
        icoll.Add("rhinoceros");
        Display(sentence, "Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':");

        Console.WriteLine("Test 16: Copy the list to an array:");
        // Create an array with the same number of
        // elements as the linked list.
        string[] sArray = new string[sentence.Count];
        sentence.CopyTo(sArray, 0);

        foreach (string s in sArray)
        {
            Console.WriteLine(s);
        }

        Console.WriteLine("Test 17: linked list Contains 'jumps' = {0}",
            sentence.Contains("jumps"));
        
        // Release all the nodes.
        sentence.Clear();

        Console.WriteLine();
        Console.WriteLine("Test 18: Cleared linked list Contains 'jumps' = {0}",
            sentence.Contains("jumps"));

        Console.ReadLine();
    }

    private static void Display(LinkedList<string> words, string test)
    {
        Console.WriteLine(test);
        foreach (string word in words)
        {
            Console.Write(word + " ");
        }
        Console.WriteLine();
        Console.WriteLine();
    }

    private static void IndicateNode(LinkedListNode<string> node, string test)
    {
        Console.WriteLine(test);
        if (node.List == null)
        {
            Console.WriteLine("Node '{0}' is not in the list.\n",
                node.Value);
            return;
        }

        StringBuilder result = new StringBuilder("(" + node.Value + ")");
        LinkedListNode<string> nodeP = node.Previous;

        while (nodeP != null)
        {
            result.Insert(0, nodeP.Value + " ");
            nodeP = nodeP.Previous;
        }

        node = node.Next;
        while (node != null)
        {
            result.Append(" " + node.Value);
            node = node.Next;
        }

        Console.WriteLine(result);
        Console.WriteLine();
    }
}

//This code example produces the following output:
//
//The linked list values:
//the fox jumps over the dog

//Test 1: Add 'today' to beginning of the list:
//today the fox jumps over the dog

//Test 2: Move first node to be last node:
//the fox jumps over the dog today

//Test 3: Change the last node to 'yesterday':
//the fox jumps over the dog yesterday

//Test 4: Move last node to be first node:
//yesterday the fox jumps over the dog

//Test 5: Indicate last occurence of 'the':
//the fox jumps over (the) dog

//Test 6: Add 'lazy' and 'old' after 'the':
//the fox jumps over (the) lazy old dog

//Test 7: Indicate the 'fox' node:
//the (fox) jumps over the lazy old dog

//Test 8: Add 'quick' and 'brown' before 'fox':
//the quick brown (fox) jumps over the lazy old dog

//Test 9: Indicate the 'dog' node:
//the quick brown fox jumps over the lazy old (dog)

//Test 10: Throw exception by adding node (fox) already in the list:
//Exception message: The LinkedList node belongs a LinkedList.

//Test 11: Move a referenced node (fox) before the current node (dog):
//the quick brown jumps over the lazy old fox (dog)

//Test 12: Remove current node (dog) and attempt to indicate it:
//Node 'dog' is not in the list.

//Test 13: Add node removed in test 11 after a referenced node (brown):
//the quick brown (dog) jumps over the lazy old fox

//Test 14: Remove node that has the value 'old':
//the quick brown dog jumps over the lazy fox

//Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':
//the quick brown dog jumps over the lazy rhinoceros

//Test 16: Copy the list to an array:
//the
//quick
//brown
//dog
//jumps
//over
//the
//lazy
//rhinoceros

//Test 17: linked list Contains 'jumps'= True

//Test 18: Cleared linked list Contains 'jumps'  = False
//
Imports System.Text
Imports System.Collections.Generic
Public Class Example

    Public Shared Sub Main()
        ' Create the link list.
        Dim words() As String = {"the", "fox", _
            "jumps", "over", "the", "dog"}
        Dim sentence As New LinkedList(Of String)(words)
        Console.WriteLine("sentence.Contains(""jumps"") = {0}", _
            sentence.Contains("jumps"))
        Display(sentence, "The linked list values:")
        ' Add the word 'today' to the beginning of the linked list.
        sentence.AddFirst("today")
        Display(sentence, "Test 1: Add 'today' to beginning of the list:")
        ' Move the first node to be the last node.
        Dim mark1 As LinkedListNode(Of String) = sentence.First
        sentence.RemoveFirst()
        sentence.AddLast(mark1)
        Display(sentence, "Test 2: Move first node to be last node:")
        ' Change the last node to 'yesterday'.
        sentence.RemoveLast()
        sentence.AddLast("yesterday")
        Display(sentence, "Test 3: Change the last node to 'yesterday':")
        ' Move the last node to be the first node.
        mark1 = sentence.Last
        sentence.RemoveLast()
        sentence.AddFirst(mark1)
        Display(sentence, "Test 4: Move last node to be first node:")
        ' Indicate the last occurence of 'the'.
        sentence.RemoveFirst()
        Dim current As LinkedListNode(Of String) = sentence.FindLast("the")
        IndicateNode(current, "Test 5: Indicate last occurence of 'the':")
        ' Add 'lazy' and 'old' after 'the' (the LinkedListNode named current).
        sentence.AddAfter(current, "old")
        sentence.AddAfter(current, "lazy")
        IndicateNode(current, "Test 6: Add 'lazy' and 'old' after 'the':")
        ' Indicate 'fox' node.
        current = sentence.Find("fox")
        IndicateNode(current, "Test 7: Indicate the 'fox' node:")
        ' Add 'quick' and 'brown' before 'fox':
        sentence.AddBefore(current, "quick")
        sentence.AddBefore(current, "brown")
        IndicateNode(current, "Test 8: Add 'quick' and 'brown' before 'fox':")
        ' Keep a reference to the current node, 'fox',
        ' and to the previous node in the list. Indicate the 'dog' node.
        mark1 = current
        Dim mark2 As LinkedListNode(Of String) = current.Previous
        current = sentence.Find("dog")
        IndicateNode(current, "Test 9: Indicate the 'dog' node:")
        ' The AddBefore method throws an InvalidOperationException
        ' if you try to add a node that already belongs to a list.
        Console.WriteLine("Test 10: Throw exception by adding node (fox) already in the list:")
        Try
            sentence.AddBefore(current, mark1)
        Catch ex As InvalidOperationException
            Console.WriteLine("Exception message: {0}", ex.Message)
        End Try
        Console.WriteLine()
        ' Remove the node referred to by mark1, and then add it
        ' before the node referred to by current.
        ' Indicate the node referred to by current.
        sentence.Remove(mark1)
        sentence.AddBefore(current, mark1)
        IndicateNode(current, "Test 11: Move a referenced node (fox) before the current node (dog):")
        ' Remove the node referred to by current. 
        sentence.Remove(current)
        IndicateNode(current, "Test 12: Remove current node (dog) and attempt to indicate it:")
        ' Add the node after the node referred to by mark2.
        sentence.AddAfter(mark2, current)
        IndicateNode(current, "Test 13: Add node removed in test 11 after a referenced node (brown):")
        ' The Remove method finds and removes the
        ' first node that that has the specified value.
        sentence.Remove("old")
        Display(sentence, "Test 14: Remove node that has the value 'old':")
        ' When the linked list is cast to ICollection(Of String),
        ' the Add method adds a node to the end of the list.
        sentence.RemoveLast()
        Dim icoll As ICollection(Of String) = sentence
        icoll.Add("rhinoceros")
        Display(sentence, "Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':")
        Console.WriteLine("Test 16: Copy the list to an array:")
        ' Create an array with the same number of
        ' elements as the inked list.
        Dim sArray() As String = New String((sentence.Count) - 1) {}
        sentence.CopyTo(sArray, 0)
        For Each s As String In sArray
            Console.WriteLine(s)
        Next

        ' Release all the nodes.
        sentence.Clear()
        Console.WriteLine()
        Console.WriteLine("Test 17: Clear linked list. Contains 'jumps' = {0}", sentence.Contains("jumps"))
        Console.ReadLine()
    End Sub

    Private Shared Sub Display(ByVal words As LinkedList(Of String), ByVal test As String)
        Console.WriteLine(test)
        For Each word As String In words
            Console.Write((word + " "))
        Next
        Console.WriteLine()
        Console.WriteLine()
    End Sub

    Private Shared Sub IndicateNode(ByVal node As LinkedListNode(Of String), ByVal test As String)
        Console.WriteLine(test)
        If IsNothing(node.List) Then
            Console.WriteLine("Node '{0}' is not in the list." & vbLf, node.Value)
            Return
        End If
        Dim result As StringBuilder = New StringBuilder(("(" _
                        + (node.Value + ")")))
        Dim nodeP As LinkedListNode(Of String) = node.Previous

        While (Not (nodeP) Is Nothing)
            result.Insert(0, (nodeP.Value + " "))
            nodeP = nodeP.Previous

        End While
        node = node.Next

        While (Not (node) Is Nothing)
            result.Append((" " + node.Value))
            node = node.Next

        End While
        Console.WriteLine(result)
        Console.WriteLine()
    End Sub
End Class
'This code example produces the following output:
'
'The linked list values:
'the fox jumps over the dog 
'Test 1: Add 'today' to beginning of the list:
'today the fox jumps over the dog

'Test 2: Move first node to be last node:
'the fox jumps over the dog today

'Test 3: Change the last node to 'yesterday':
'the fox jumps over the dog yesterday

'Test 4: Move last node to be first node:
'yesterday the fox jumps over the dog

'Test 5: Indicate last occurence of 'the':
'the fox jumps over (the) dog

'Test 6: Add 'lazy' and 'old' after 'the':
'the fox jumps over (the) lazy old dog

'Test 7: Indicate the 'fox' node:
'the (fox) jumps over the lazy old dog

'Test 8: Add 'quick' and 'brown' before 'fox':
'the quick brown (fox) jumps over the lazy old dog

'Test 9: Indicate the 'dog' node:
'the quick brown fox jumps over the lazy old (dog)

'Test 10: Throw exception by adding node (fox) already in the list:
'Exception message: The LinkedList node belongs a LinkedList.

'Test 11: Move a referenced node (fox) before the current node (dog):
'the quick brown jumps over the lazy old fox (dog)

'Test 12: Remove current node (dog) and attempt to indicate it:
'Node 'dog' is not in the list.

'Test 13: Add node removed in test 11 after a referenced node (brown):
'the quick brown (dog) jumps over the lazy old fox

'Test 14: Remove node that has the value 'old':
'the quick brown dog jumps over the lazy fox 

'Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':
'the quick brown dog jumps over the lazy rhinoceros

'Test 16: Copy the list to an array:
'the
'quick
'brown
'dog
'jumps
'over
'the
'lazy
'rhinoceros

'Test 17: Clear linked list. Contains 'jumps' = False
'

注解

LinkedList<T> 是常规用途的链接列表。 它支持枚举器并实现 ICollection 接口,与.NET Framework中的其他集合类一致。

LinkedList<T> 提供 类型的 LinkedListNode<T>单独节点,因此插入和删除是 O (1) 操作。

可以在同一列表中或另一个列表中删除节点并重新插入它们,这会导致堆上没有分配其他对象。 由于列表还维护内部计数,因此获取 Count 属性是一个 O (1) 操作。

对象中的每个 LinkedList<T> 节点的类型为 LinkedListNode<T>LinkedList<T>由于 是双重链接的,因此每个节点前向指向 节点,Next向后指向 Previous 节点。

同时创建节点及其值时,包含引用类型的Lists性能更好。 LinkedList<T> 接受 null 作为引用类型的有效 Value 属性,并允许重复值。

LinkedList<T>如果 为空,则 FirstLast 属性包含 null

LinkedList<T> 不支持链接、拆分、周期或其他可能使列表处于不一致状态的功能。 列表在单个线程上保持一致。 支持的唯一多线程方案 LinkedList<T> 是多线程读取操作。

构造函数

LinkedList<T>()

初始化为空的 LinkedList<T> 类的新实例。

LinkedList<T>(IEnumerable<T>)

初始化 LinkedList<T> 类的新实例,该实例包含从指定的 IEnumerable 中复制的元素并且其容量足以容纳所复制的元素数。

LinkedList<T>(SerializationInfo, StreamingContext)
已过时.

初始化 LinkedList<T> 类的新实例,该实例可使用指定的 SerializationInfoStreamingContext 进行序列化。

属性

Count

获取 LinkedList<T> 中实际包含的节点数。

First

获取 LinkedList<T> 的第一个节点。

Last

获取 LinkedList<T> 的最后一个节点。

方法

AddAfter(LinkedListNode<T>, LinkedListNode<T>)

LinkedList<T> 中指定的现有节点后添加指定的新节点。

AddAfter(LinkedListNode<T>, T)

LinkedList<T> 中指定的现有节点后添加包含指定值的新节点。

AddBefore(LinkedListNode<T>, LinkedListNode<T>)

LinkedList<T> 中指定的现有节点前添加指定的新节点。

AddBefore(LinkedListNode<T>, T)

LinkedList<T> 中指定的现有节点前添加包含指定值的新节点。

AddFirst(LinkedListNode<T>)

LinkedList<T> 的开头处添加指定的新节点。

AddFirst(T)

LinkedList<T> 的开头处添加包含指定值的新节点。

AddLast(LinkedListNode<T>)

LinkedList<T> 的结尾处添加指定的新节点。

AddLast(T)

LinkedList<T> 的结尾处添加包含指定值的新节点。

Clear()

LinkedList<T> 中移除所有节点。

Contains(T)

确定某值是否在 LinkedList<T> 中。

CopyTo(T[], Int32)

从目标数组的指定索引处开始将整个 LinkedList<T> 复制到兼容的一维 Array

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Find(T)

查找包含指定值的第一个节点。

FindLast(T)

查找包含指定值的最后一个节点。

GetEnumerator()

返回循环访问 LinkedList<T> 的枚举数。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)
已过时.

实现 ISerializable 接口,并返回序列化 LinkedList<T> 实例所需的数据。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnDeserialization(Object)

实现 ISerializable 接口,并在完成反序列化之后引发反序列化事件。

Remove(LinkedListNode<T>)

LinkedList<T> 中移除指定的节点。

Remove(T)

LinkedList<T> 中移除指定值的第一个匹配项。

RemoveFirst()

移除位于 LinkedList<T> 开头处的节点。

RemoveLast()

移除位于 LinkedList<T> 结尾处的节点。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

ICollection.CopyTo(Array, Int32)

从特定的 ICollection 索引开始,将 Array 的元素复制到一个 Array 中。

ICollection.IsSynchronized

获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。

ICollection.SyncRoot

获取可用于同步对 ICollection 的访问的对象。

ICollection<T>.Add(T)

将项添加到 ICollection<T> 的结尾处。

ICollection<T>.IsReadOnly

获取一个值,该值指示 ICollection<T> 是否为只读。

IEnumerable.GetEnumerator()

返回一个将链表作为集合进行循环访问的枚举数。

IEnumerable<T>.GetEnumerator()

返回循环访问集合的枚举数。

扩展方法

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

FrozenDictionary<TKey,TValue>根据指定的键选择器函数从 IEnumerable<T> 创建 。

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

根据指定的键选择器和元素选择器函数,从 IEnumerable<T> 创建一个 FrozenDictionary<TKey,TValue>

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

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

ToImmutableArray<TSource>(IEnumerable<TSource>)

从指定的集合创建一个不可变数组。

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

通过向源键应用转换函数,从现有元素集合构造一个不可变字典。

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

基于对序列进行某种形式的转换来构造一个不可变字典。

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

枚举并转换序列,然后生成其内容的不可变字典。

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

枚举并转换序列,然后使用指定的键比较器生成其内容的不可变字典。

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

枚举并转换序列,然后使用指定的键和值比较器生成其内容的不可变字典。

ToImmutableHashSet<TSource>(IEnumerable<TSource>)

枚举序列,并生成其内容的不可变哈希集。

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

枚举序列,生成其内容的不可变哈希集,并为集类型使用指定的相等性比较器。

ToImmutableList<TSource>(IEnumerable<TSource>)

枚举序列,并生成其内容的不可变列表。

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

枚举并转换序列,然后生成其内容的不可变排序字典。

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

枚举并转换序列,然后使用指定的键比较器生成其内容的不可变排序字典。

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

枚举并转换序列,然后使用指定的键和值比较器生成其内容的不可变排序字典。

ToImmutableSortedSet<TSource>(IEnumerable<TSource>)

枚举序列,并生成其内容的不可变排序集。

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

枚举序列,生成其内容的不可变排序集,并使用指定的比较器。

CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRow

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

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRow

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

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRow

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

对序列应用累加器函数。

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

对序列应用累加器函数。 将指定的种子值用作累加器初始值。

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

对序列应用累加器函数。 将指定的种子值用作累加器的初始值,并使用指定的函数选择结果值。

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

表示双重链接列表。

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

表示双重链接列表。

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

确定序列中的所有元素是否都满足条件。

Any<TSource>(IEnumerable<TSource>)

确定序列是否包含任何元素。

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

确定序列中是否存在任意一个元素满足条件。

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

将一个值追加到序列末尾。

AsEnumerable<TSource>(IEnumerable<TSource>)

返回类型化为 IEnumerable<T> 的输入。

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

计算 Decimal 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算 Double 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算 Int32 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算 Int64 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Decimal 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Double 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Int32 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Int64 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Single 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算 Single 值序列的平均值,这些值可通过对输入序列的每个元素调用转换函数获得。

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。

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

将序列的元素拆分为最多 size大小的区块。

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

连接两个序列。

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

通过使用默认的相等比较器确定序列是否包含指定的元素。

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

通过使用指定的 IEqualityComparer<T> 确定序列是否包含指定的元素。

Count<TSource>(IEnumerable<TSource>)

返回序列中的元素数量。

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

返回表示在指定的序列中满足条件的元素数量的数字。

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

表示双重链接列表。

DefaultIfEmpty<TSource>(IEnumerable<TSource>)

返回指定序列中的元素;如果序列为空,则返回单一实例集合中的类型参数的默认值。

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

返回指定序列中的元素;如果序列为空,则返回单一实例集合中的指定值。

Distinct<TSource>(IEnumerable<TSource>)

通过使用默认的相等比较器对值进行比较,返回序列中的非重复元素。

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

通过使用指定的 IEqualityComparer<T> 对值进行比较,返回序列中的非重复元素。

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

根据指定的键选择器函数从序列中返回不同的元素。

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

根据指定的键选择器函数返回序列中的不同元素,并使用指定的比较器比较键。

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

返回序列中指定索引处的元素。

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

返回序列中指定索引处的元素。

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

返回序列中指定索引处的元素;如果索引超出范围,则返回默认值。

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

返回序列中指定索引处的元素;如果索引超出范围,则返回默认值。

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

通过使用默认的相等比较器对值进行比较,生成两个序列的差集。

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

通过使用指定的 IEqualityComparer<T> 对值进行比较,生成两个序列的差集。

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

根据指定的键选择器函数生成两个序列的集差。

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

根据指定的键选择器函数生成两个序列的集差。

First<TSource>(IEnumerable<TSource>)

返回序列中的第一个元素。

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

返回序列中满足指定条件的第一个元素。

FirstOrDefault<TSource>(IEnumerable<TSource>)

返回序列中的第一个元素;如果序列中不包含任何元素,则返回默认值。

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

返回序列的第一个元素,如果序列不包含任何元素,则返回指定的默认值。

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

返回序列中满足条件的第一个元素;如果未找到这样的元素,则返回默认值。

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

返回序列中满足条件的第一个元素;如果未找到此类元素,则返回指定的默认值。

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

根据指定的键选择器函数对序列中的元素进行分组。

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

根据指定的键选择器函数对序列中的元素进行分组,并使用指定的比较器对键进行比较。

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

根据指定的键选择器函数对序列中的元素进行分组,并且通过使用指定的函数对每个组中的元素进行投影。

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

根据键选择器函数对序列中的元素进行分组。 通过使用比较器对键进行比较,并且通过使用指定的函数对每个组的元素进行投影。

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

根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。

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

根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。 通过使用指定的比较器对键进行比较。

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

根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。 通过使用指定的函数对每个组的元素进行投影。

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

根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。 通过使用指定的比较器对键值进行比较,并且通过使用指定的函数对每个组的元素进行投影。

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

基于键值等同性对两个序列的元素进行关联,并对结果进行分组。 使用默认的相等比较器对键进行比较。

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

基于键值等同性对两个序列的元素进行关联,并对结果进行分组。 使用指定的 IEqualityComparer<T> 对键进行比较。

Index<TSource>(IEnumerable<TSource>)

表示双重链接列表。

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

通过使用默认的相等比较器对值进行比较,生成两个序列的交集。

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

通过使用指定的 IEqualityComparer<T> 对值进行比较,生成两个序列的交集。

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

根据指定的键选择器函数生成两个序列的集合交集。

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

根据指定的键选择器函数生成两个序列的集合交集。

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

基于匹配键对两个序列的元素进行关联。 使用默认的相等比较器对键进行比较。

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

基于匹配键对两个序列的元素进行关联。 使用指定的 IEqualityComparer<T> 对键进行比较。

Last<TSource>(IEnumerable<TSource>)

返回序列的最后一个元素。

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

返回序列中满足指定条件的最后一个元素。

LastOrDefault<TSource>(IEnumerable<TSource>)

返回序列中的最后一个元素;如果序列中不包含任何元素,则返回默认值。

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

返回序列的最后一个元素,如果序列不包含任何元素,则返回指定的默认值。

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

返回序列中满足条件的最后一个元素;如果未找到这样的元素,则返回默认值。

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

返回序列中满足条件的最后一个元素;如果未找到此类元素,则返回指定的默认值。

LongCount<TSource>(IEnumerable<TSource>)

返回表示序列中元素总数的 Int64

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

返回表示序列中满足条件的元素的数量的 Int64

Max<TSource>(IEnumerable<TSource>)

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

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

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

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

对序列中的每个元素调用转换函数,并返回最大的 Decimal 值。

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

对序列中的每个元素调用转换函数,并返回最大的 Double 值。

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

对序列中的每个元素调用转换函数,并返回最大的 Int32 值。

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

对序列中的每个元素调用转换函数,并返回最大的 Int64 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最大的 Decimal 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最大的 Double 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最大的 Int32 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最大的 Int64 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最大的 Single 值。

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

对序列中的每个元素调用转换函数,并返回最大的 Single 值。

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

对序列中的每个元素调用转换函数,并返回最大结果值。

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

根据指定的键选择器函数返回泛型序列中的最大值。

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

根据指定的键选择器函数和键比较器返回泛型序列中的最大值。

Min<TSource>(IEnumerable<TSource>)

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

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

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

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

对序列中的每个元素调用转换函数,并返回最小的 Decimal 值。

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

对序列中的每个元素调用转换函数,并返回最小的 Double 值。

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

对序列中的每个元素调用转换函数,并返回最小的 Int32 值。

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

对序列中的每个元素调用转换函数,并返回最小的 Int64 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Decimal 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Double 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Int32 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Int64 值。

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

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Single 值。

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

对序列中的每个元素调用转换函数,并返回最小的 Single 值。

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

对序列中的每个元素调用转换函数,并返回最小结果值。

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

根据指定的键选择器函数返回泛型序列中的最小值。

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

根据指定的键选择器函数和键比较器返回泛型序列中的最小值。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

Order<T>(IEnumerable<T>)

按升序对序列的元素进行排序。

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

按升序对序列的元素进行排序。

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

根据键按升序对序列的元素进行排序。

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

使用指定的比较器按升序对序列的元素进行排序。

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

根据键按降序对序列的元素进行排序。

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

使用指定的比较器按降序对序列的元素排序。

OrderDescending<T>(IEnumerable<T>)

按降序对序列的元素排序。

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

按降序对序列的元素排序。

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

向序列的开头添加值。

Reverse<TSource>(IEnumerable<TSource>)

反转序列中元素的顺序。

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

将序列中的每个元素投影到新表单。

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

通过合并元素的索引,将序列的每个元素投影到新窗体中。

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

将序列的每个元素投影到 IEnumerable<T> 并将结果序列合并为一个序列。

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

将序列的每个元素投影到 IEnumerable<T> 并将结果序列合并为一个序列。 每个源元素的索引用于该元素的投影表。

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

将序列的每个元素投影到 IEnumerable<T>,并将结果序列合并为一个序列,并对其中每个元素调用结果选择器函数。

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

将序列的每个元素投影到 IEnumerable<T>,并将结果序列合并为一个序列,并对其中每个元素调用结果选择器函数。 每个源元素的索引用于该元素的中间投影表。

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

通过使用相应类型的默认相等比较器对序列的元素进行比较,以确定两个序列是否相等。

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

通过使用指定的 IEqualityComparer<T> 来比较两个序列的元素,以确定这两个序列是否相等。

Single<TSource>(IEnumerable<TSource>)

返回序列的唯一元素;如果该序列并非恰好包含一个元素,则会引发异常。

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

返回序列中满足指定条件的唯一元素;如果有多个这样的元素存在,则会引发异常。

SingleOrDefault<TSource>(IEnumerable<TSource>)

返回序列中的唯一元素;如果该序列为空,则返回默认值;如果该序列包含多个元素,此方法将引发异常。

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

返回序列的唯一元素,如果序列为空,则返回指定的默认值;如果序列中有多个元素,此方法将引发异常。

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

返回序列中满足指定条件的唯一元素;如果这类元素不存在,则返回默认值;如果有多个元素满足该条件,此方法将引发异常。

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

返回序列中满足指定条件的唯一元素;如果没有此类元素,则返回指定的默认值;如果多个元素满足条件,此方法将引发异常。

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

跳过序列中指定数量的元素,然后返回剩余的元素。

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

返回一个新的可枚举集合,它包含 source 中的元素,但省略了源集合中的 count 个元素。

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

如果指定的条件为 true,则跳过序列中的元素,然后返回剩余的元素。

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

如果指定的条件为 true,则跳过序列中的元素,然后返回剩余的元素。 将在谓词函数的逻辑中使用元素的索引。

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

计算 Decimal 值序列的总和,这些值可通过对输入序列中的每个元素调用转换函数获得。

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

计算 Double 值序列的总和,这些值可通过对输入序列中的每个元素调用转换函数获得。

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

计算 Int32 值序列的总和,这些值可通过对输入序列中的每个元素调用转换函数获得。

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

计算 Int64 值序列的总和,这些值可通过对输入序列中的每个元素调用转换函数获得。

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

计算可以为 null 的 Decimal 值序列的总和,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Double 值序列的总和,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Int32 值序列的总和,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Int64 值序列的总和,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算可以为 null 的 Single 值序列的总和,这些值可通过对输入序列的每个元素调用转换函数获得。

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

计算 Single 值序列的总和,这些值可通过对输入序列中的每个元素调用转换函数获得。

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

从序列的开头返回指定数量的相邻元素。

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

从序列中返回指定范围的连续元素。

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

返回一个新的可枚举集合,它包含 count 中的最后 source 个元素。

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

只要指定的条件为 true,就会返回序列的元素。

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

只要指定的条件为 true,就会返回序列的元素。 将在谓词函数的逻辑中使用元素的索引。

ToArray<TSource>(IEnumerable<TSource>)

IEnumerable<T> 中创建数组。

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

根据指定的键选择器函数,从 IEnumerable<T> 创建一个 Dictionary<TKey,TValue>

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

根据指定的键选择器函数和键比较器,从 IEnumerable<T> 创建一个 Dictionary<TKey,TValue>

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

根据指定的键选择器和元素选择器函数,从 IEnumerable<T> 创建一个 Dictionary<TKey,TValue>

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

根据指定的键选择器函数、比较器和元素选择器函数,从 IEnumerable<T> 创建一个 Dictionary<TKey,TValue>

ToHashSet<TSource>(IEnumerable<TSource>)

IEnumerable<T> 创建一个 HashSet<T>

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

使用 comparer 通过 IEnumerable<T> 创建 HashSet<T>,以用于比较键。

ToList<TSource>(IEnumerable<TSource>)

IEnumerable<T> 创建一个 List<T>

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

根据指定的键选择器函数,从 IEnumerable<T> 创建一个 Lookup<TKey,TElement>

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

根据指定的键选择器函数和键比较器,从 IEnumerable<T> 创建一个 Lookup<TKey,TElement>

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

根据指定的键选择器和元素选择器函数,从 IEnumerable<T> 创建一个 Lookup<TKey,TElement>

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

根据指定的键选择器函数、比较器和元素选择器函数,从 IEnumerable<T> 创建一个 Lookup<TKey,TElement>

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

尝试在不强制枚举的情况下确定序列中的元素数。

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

通过使用默认的相等比较器,生成两个序列的并集。

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

通过使用指定的 IEqualityComparer<T> 生成两个序列的并集。

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

根据指定的键选择器函数生成两个序列的集联合。

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

根据指定的键选择器函数生成两个序列的集联合。

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

基于谓词筛选值序列。

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

基于谓词筛选值序列。 将在谓词函数的逻辑中使用每个元素的索引。

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

使用两个指定序列中的元素生成元组序列。

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

使用三个指定序列中的元素生成元组序列。

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

将指定函数应用于两个序列的对应元素,以生成结果序列。

AsParallel(IEnumerable)

启用查询的并行化。

AsParallel<TSource>(IEnumerable<TSource>)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

AsQueryable<TElement>(IEnumerable<TElement>)

将泛型 IEnumerable<T> 转换为泛型 IQueryable<T>

Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。

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

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。 集合中仅包括具有匹配 XName 的元素。

DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。

Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。

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

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。 集合中仅包括具有匹配 XName 的元素。

Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。

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

返回源集合中经过筛选的每个元素和文档的子元素集合。 集合中仅包括具有匹配 XName 的元素。

InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。

Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。

Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。

适用于

线程安全性

此类型并非线程安全。 LinkedList<T>如果需要由多个线程访问 ,则需要实现自己的同步机制。

LinkedList<T>只要集合未修改,就可以同时支持多个读取器。 即便如此,通过集合枚举本质上也不是线程安全的过程。 在枚举与写入访问权限竞争的极少数情况下,必须在整个枚举期间锁定集合。 若要允许多个线程访问集合以进行读写操作,则必须实现自己的同步。

另请参阅