LinkedList<T> LinkedList<T> LinkedList<T> LinkedList<T> Class

Definition

Stellt eine doppelt verknüpfte Liste dar.Represents a doubly linked list.

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
[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
type LinkedList<'T> = class
    interface ICollection<'T>
    interface ICollection
    interface IReadOnlyCollection<'T>
    interface ISerializable
    interface IDeserializationCallback
    interface seq<'T>
    interface IEnumerable
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), IReadOnlyCollection(Of T), ISerializable

Typparameter

T

Gibt den Elementtyp der verknüpften Liste an.Specifies the element type of the linked list.

Vererbung
LinkedList<T>LinkedList<T>LinkedList<T>LinkedList<T>
Attribute
Implementiert

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, viele Funktionen von der LinkedList<T> Klasse.The following code example demonstrates many features of the LinkedList<T> class.

#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:");
        Console.WriteLine("sentence.Contains(\"jumps\") = {0}",
            sentence.Contains("jumps"));

        // 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.
        string[] sArray = new string[sentence.Count];
        sentence.CopyTo(sArray, 0);

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

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

        Console.WriteLine();
        Console.WriteLine("Test 17: Clear 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: Clear linked list. Contains 'jumps' = False
//
Imports System
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
'

Hinweise

LinkedList<T> ist eine vielfältig einsetzbare verknüpfte Liste.LinkedList<T> is a general-purpose linked list. Es unterstützt, Enumeratoren und implementiert die ICollection Schnittstelle, die konsistent mit anderen Auflistungsklassen in .NET Framework.It supports enumerators and implements the ICollection interface, consistent with other collection classes in the .NET Framework.

LinkedList<T> stellt separate Knoten vom Typ LinkedListNode<T>, sodass Einfüge- und Entfernvorgänge o(1)-Einfüge-Löschvorgänge sind.LinkedList<T> provides separate nodes of type LinkedListNode<T>, so insertion and removal are O(1) operations.

Entfernen Sie Knoten, und wieder einfügen und entweder in derselben Liste oder in einer anderen Liste, sodass keine zusätzliche Objekte im Heap zugeordnet.You can remove nodes and reinsert them, either in the same list or in another list, which results in no additional objects allocated on the heap. Da die Liste auch eine interne Anzahl verwaltet werden, Abrufen der Count -Eigenschaft ist ein o(1)-Vorgang.Because the list also maintains an internal count, getting the Count property is an O(1) operation.

Jeder Knoten in einem LinkedList<T> Objekt weist den Typ LinkedListNode<T>.Each node in a LinkedList<T> object is of the type LinkedListNode<T>. Da die LinkedList<T> doppelt verknüpft ist, kann jeder Knoten verweist weiterleiten, die Next Knoten als auch auf die Previous Knoten.Because the LinkedList<T> is doubly linked, each node points forward to the Next node and backward to the Previous node.

Listen, die Verweistypen enthalten eine bessere Leistung, wenn ein Knoten und dessen Wert zur gleichen Zeit erstellt werden.Lists that contain reference types perform better when a node and its value are created at the same time. LinkedList<T> akzeptiert null als gültiger Value für Verweis und lässt doppelte Werte.LinkedList<T> accepts null as a valid Value property for reference types and allows duplicate values.

Wenn die LinkedList<T> leer ist, die First und Last Eigenschaften enthalten null.If the LinkedList<T> is empty, the First and Last properties contain null.

Die LinkedList<T> verketten, aufteilen, Zyklen oder andere Features, die die Liste in einem inkonsistenten Zustand versetzen können-Klasse nicht unterstützt.The LinkedList<T> class does not support chaining, splitting, cycles, or other features that can leave the list in an inconsistent state. Die Liste bleibt konsistent auf einem einzelnen Thread.The list remains consistent on a single thread. Die von unterstützt nur Multithread-Szenario LinkedList<T> ist Multithread-Lesevorgänge.The only multithreaded scenario supported by LinkedList<T> is multithreaded read operations.

Konstruktoren

LinkedList<T>() LinkedList<T>() LinkedList<T>() LinkedList<T>()

Initialisiert eine neue, leere Instanz der LinkedList<T>-Klasse.Initializes a new instance of the LinkedList<T> class that is empty.

LinkedList<T>(IEnumerable<T>) LinkedList<T>(IEnumerable<T>) LinkedList<T>(IEnumerable<T>) LinkedList<T>(IEnumerable<T>)

Initialisiert eine neue Instanz der LinkedList<T>-Klasse, die aus dem angegebenen IEnumerable kopierte Elemente enthält und eine ausreichende Kapazität für die Anzahl der kopierten Elemente aufweist.Initializes a new instance of the LinkedList<T> class that contains elements copied from the specified IEnumerable and has sufficient capacity to accommodate the number of elements copied.

LinkedList<T>(SerializationInfo, StreamingContext) LinkedList<T>(SerializationInfo, StreamingContext) LinkedList<T>(SerializationInfo, StreamingContext) LinkedList<T>(SerializationInfo, StreamingContext)

Initialisiert eine neue Instanz der serialisierbaren LinkedList<T>-Klasse mit der angegebenen SerializationInfo und dem angegebenen StreamingContext.Initializes a new instance of the LinkedList<T> class that is serializable with the specified SerializationInfo and StreamingContext.

Eigenschaften

Count Count Count Count

Ruft die Anzahl der Knoten ab, die tatsächlich in der LinkedList<T> enthalten sind.Gets the number of nodes actually contained in the LinkedList<T>.

First First First First

Ruft den ersten Knoten der LinkedList<T> ab.Gets the first node of the LinkedList<T>.

Last Last Last Last

Ruft den letzten Knoten der LinkedList<T> ab.Gets the last node of the LinkedList<T>.

Methoden

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

Fügt den angegebenen neuen Knoten nach dem angegebenen vorhandenen Knoten in der LinkedList<T> hinzu.Adds the specified new node after the specified existing node in the LinkedList<T>.

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

Fügt nach dem angegebenen vorhandenen Knoten in der LinkedList<T> einen neuen Knoten mit dem angegebenen Wert hinzu.Adds a new node containing the specified value after the specified existing node in the LinkedList<T>.

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

Fügt den angegebenen neuen Knoten vor dem angegebenen vorhandenen Knoten in der LinkedList<T> hinzu.Adds the specified new node before the specified existing node in the LinkedList<T>.

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

Fügt vor dem angegebenen vorhandenen Knoten in der LinkedList<T> einen neuen Knoten mit dem angegebenen Wert hinzu.Adds a new node containing the specified value before the specified existing node in the LinkedList<T>.

AddFirst(LinkedListNode<T>) AddFirst(LinkedListNode<T>) AddFirst(LinkedListNode<T>) AddFirst(LinkedListNode<T>)

Fügt am Anfang der LinkedList<T> den angegebenen neuen Knoten hinzu.Adds the specified new node at the start of the LinkedList<T>.

AddFirst(T) AddFirst(T) AddFirst(T) AddFirst(T)

Fügt am Anfang der LinkedList<T> einen neuen Knoten mit dem angegebenen Wert hinzu.Adds a new node containing the specified value at the start of the LinkedList<T>.

AddLast(LinkedListNode<T>) AddLast(LinkedListNode<T>) AddLast(LinkedListNode<T>) AddLast(LinkedListNode<T>)

Fügt am Ende der LinkedList<T> den angegebenen neuen Knoten hinzu.Adds the specified new node at the end of the LinkedList<T>.

AddLast(T) AddLast(T) AddLast(T) AddLast(T)

Fügt am Ende der LinkedList<T> einen neuen Knoten mit dem angegebenen Wert hinzu.Adds a new node containing the specified value at the end of the LinkedList<T>.

Clear() Clear() Clear() Clear()

Entfernt alle Knoten aus der LinkedList<T>.Removes all nodes from the LinkedList<T>.

Contains(T) Contains(T) Contains(T) Contains(T)

Bestimmt, ob sich ein Wert in der LinkedList<T> befindet.Determines whether a value is in the LinkedList<T>.

CopyTo(T[], Int32) CopyTo(T[], Int32) CopyTo(T[], Int32) CopyTo(T[], Int32)

Kopiert die gesamte LinkedList<T>-Instanz in ein kompatibles eindimensionales Array, beginnend am angegebenen Index des Zielarrays.Copies the entire LinkedList<T> to a compatible one-dimensional Array, starting at the specified index of the target array.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

(Inherited from Object)
Find(T) Find(T) Find(T) Find(T)

Sucht den ersten Knoten, der den angegebenen Wert enthält.Finds the first node that contains the specified value.

FindLast(T) FindLast(T) FindLast(T) FindLast(T)

Sucht den letzten Knoten, der den angegebenen Wert enthält.Finds the last node that contains the specified value.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Gibt einen Enumerator zurück, der die LinkedList<T> durchläuft.Returns an enumerator that iterates through the LinkedList<T>.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Standardhashfunktion.Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

Implementiert die ISerializable-Schnittstelle und gibt die zum Serialisieren der LinkedList<T>-Instanz erforderlichen Daten zurück.Implements the ISerializable interface and returns the data needed to serialize the LinkedList<T> instance.

GetType() GetType() GetType() GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialization(Object) OnDeserialization(Object) OnDeserialization(Object) OnDeserialization(Object)

Implementiert die ISerializable-Schnittstelle und löst das Deserialisierungsereignis aus, sobald die Deserialisierung abgeschlossen ist.Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.

Remove(LinkedListNode<T>) Remove(LinkedListNode<T>) Remove(LinkedListNode<T>) Remove(LinkedListNode<T>)

Entfernt den angegebenen Knoten aus der LinkedList<T>.Removes the specified node from the LinkedList<T>.

Remove(T) Remove(T) Remove(T) Remove(T)

Entfernt das erste Vorkommen des angegebenen Werts aus der LinkedList<T>.Removes the first occurrence of the specified value from the LinkedList<T>.

RemoveFirst() RemoveFirst() RemoveFirst() RemoveFirst()

Entfernt den Knoten am Anfang der LinkedList<T>.Removes the node at the start of the LinkedList<T>.

RemoveLast() RemoveLast() RemoveLast() RemoveLast()

Entfernt den Knoten am Ende der LinkedList<T>.Removes the node at the end of the LinkedList<T>.

ToString() ToString() ToString() ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)

Explizite Schnittstellenimplementierungen

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

Kopiert die Elemente der ICollection in ein Array, beginnend bei einem bestimmten Array-Index.Copies the elements of the ICollection to an Array, starting at a particular Array index.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

Ruft einen Wert ab, der angibt, ob der Zugriff auf die ICollection synchronisiert (threadsicher) ist.Gets a value indicating whether access to the ICollection is synchronized (thread safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

Ruft ein Objekt ab, mit dem der Zugriff auf ICollection synchronisiert werden kann.Gets an object that can be used to synchronize access to the ICollection.

ICollection<T>.Add(T) ICollection<T>.Add(T) ICollection<T>.Add(T) ICollection<T>.Add(T)

Fügt am Ende der ICollection<T> ein Element hinzu.Adds an item at the end of the ICollection<T>.

ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly

Ruft einen Wert ab, der angibt, ob das ICollection<T> schreibgeschützt ist.Gets a value indicating whether the ICollection<T> is read-only.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Gibt einen Enumerator zurück, der die verknüpfte Liste als Auflistung durchläuft.Returns an enumerator that iterates through the linked list as a collection.

IEnumerable<T>.GetEnumerator() IEnumerable<T>.GetEnumerator() IEnumerable<T>.GetEnumerator() IEnumerable<T>.GetEnumerator()

Gibt einen Enumerator zurück, der eine Auflistung durchläuft.Returns an enumerator that iterates through a collection.

Extension Methods

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

Gibt eine DataTable , enthält die Kopien der DataRow Objekte, wenn ein IEnumerable<T> Objekt, in dem der generische Parameter T ist DataRow.Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

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

Kopien DataRow Objekte mit dem angegebenen DataTable, wenn ein IEnumerable<T> Objekt, in dem der generische Parameter T ist DataRow.Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

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

Kopien DataRow Objekte mit dem angegebenen DataTable, wenn ein IEnumerable<T> Objekt, in dem der generische Parameter T ist DataRow.Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Wandelt die Elemente eines IEnumerable in den angegebenen Typ umCasts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filtert die Elemente eines IEnumerable anhand eines angegebenen TypsFilters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Ermöglicht die Parallelisierung einer Abfrage.Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Konvertiert eine IEnumerable auf eine IQueryable.Converts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

Gibt eine Auflistung von Elementen zurück, die die übergeordneten Elemente der einzelnen Knoten in der Quellauflistung enthält.Returns a collection of elements that contains the ancestors of every node in the source collection.

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

Gibt eine gefilterte Auflistung von Elementen zurück, die die übergeordneten Elemente der einzelnen Knoten in der Quellauflistung enthält.Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Nur Elemente, die über einen übereinstimmenden XName verfügen, sind in der Auflistung enthalten.Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

Gibt eine Auflistung der Nachfolgerknoten jedes Dokuments und Elements in der Quellauflistung zurück.Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

Gibt eine Auflistung von Elementen zurück, die die Nachfolgerelemente jedes Elements und Dokuments in der Quellauflistung enthält.Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

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

Gibt eine gefilterte Auflistung von Elementen zurück, die die Nachfolgerelemente jedes Elements und Dokuments in der Quellauflistung enthält.Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Nur Elemente, die über einen übereinstimmenden XName verfügen, sind in der Auflistung enthalten.Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

Gibt eine Auflistung der untergeordneten Elemente jedes Elements und Dokuments in der Quellauflistung zurück.Returns a collection of the child elements of every element and document in the source collection.

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

Gibt eine gefilterte Auflistung der untergeordneten Elemente jedes Elements und Dokuments in der Quellauflistung zurück.Returns a filtered collection of the child elements of every element and document in the source collection. Nur Elemente, die über einen übereinstimmenden XName verfügen, sind in der Auflistung enthalten.Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

Gibt eine in Dokumentreihenfolge sortierte Auflistung von Knoten zurück, die alle Knoten in der Quellauflistung enthält.Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

Gibt eine Auflistung der untergeordneten Knoten jedes Dokuments und Elements in der Quellauflistung zurück.Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

Entfernt jeden Knoten in der Quellauflistung aus seinem übergeordneten Knoten.Removes every node in the source collection from its parent node.

Gilt für:

Threadsicherheit

Dieser Typ ist nicht threadsicher.This type is not thread safe. Wenn die LinkedList<T> von mehreren Threads zugegriffen werden muss Sie ihre eigenen Synchronisierungsmechanismen implementieren müssen.If the LinkedList<T> needs to be accessed by multiple threads, you will need to implement their own synchronization mechanism.

Ein LinkedList<T> gleichzeitige Unterstützung für mehrere Reader, solange die Auflistung nicht geändert wird.A LinkedList<T> can support multiple readers concurrently, as long as the collection is not modified. Trotzdem ist die Enumeration einer Auflistung systemintern keine threadsichere Prozedur.Even so, enumerating through a collection is intrinsically not a thread-safe procedure. In dem seltenen Fall, in denen eine Enumeration mit Schreibzugriffe stellt fest, muss die Auflistung während der gesamten Enumeration gesperrt werden.In the rare case where an enumeration contends with write accesses, the collection must be locked during the entire enumeration. Um den Lese- und Schreibzugriff auf diese Auflistung durch mehrere Threads zuzulassen, müssen Sie eine eigene Synchronisierung implementieren.To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

Siehe auch