LinkedList<T> Konstruktory

Definice

Inicializuje novou instanci LinkedList<T> třídy.

Přetížení

Name Description
LinkedList<T>()

Inicializuje novou instanci LinkedList<T> třídy, která je prázdná.

LinkedList<T>(IEnumerable<T>)

Inicializuje novou instanci LinkedList<T> třídy, která obsahuje prvky zkopírované ze zadaného IEnumerable a má dostatečnou kapacitu pro přizpůsobení počtu zkopírovaných prvků.

LinkedList<T>(SerializationInfo, StreamingContext)
Zastaralé.

Inicializuje novou instanci LinkedList<T> třídy, která je serializovatelná se zadaným SerializationInfo a StreamingContext.

LinkedList<T>()

Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs

Inicializuje novou instanci LinkedList<T> třídy, která je prázdná.

public:
 LinkedList();
public LinkedList();
Public Sub New ()

Příklady

Následující příklad kódu vytvoří a inicializuje LinkedList<T> typ String, přidá několik uzlů a pak zobrazí jeho obsah.

using System;
using System.Collections;
using System.Collections.Generic;

public class GenericCollection
{
    public static void Main()
    {
        // Create and initialize a new LinkedList.
        LinkedList<String> ll = new LinkedList<String>();
        ll.AddLast("red");
        ll.AddLast("orange");
        ll.AddLast("yellow");
        ll.AddLast("orange");

        // Display the contents of the LinkedList.
        if (ll.Count > 0)
        {
            Console.WriteLine("The first item in the list is {0}.", ll.First.Value);
            Console.WriteLine("The last item in the list is {0}.", ll.Last.Value);

            Console.WriteLine("The LinkedList contains:");
            foreach (String s in ll)
                Console.WriteLine("   {0}", s);
        }
        else
        {
            Console.WriteLine("The LinkedList is empty.");
        }
    }
}

/* This code produces the following output.

The first item in the list is red.
The last item in the list is orange.
The LinkedList contains:
   red
   orange
   yellow
   orange
*/
Imports System.Collections
Imports System.Collections.Generic

Public Class GenericCollection

    Public Shared Sub Main()

        ' Create and initialize a new LinkedList.
        Dim ll As New LinkedList(Of String)()
        ll.AddLast("red")
        ll.AddLast("orange")
        ll.AddLast("yellow")
        ll.AddLast("orange")

        ' Display the contents of the LinkedList.
        If ll.Count > 0 Then
            Console.WriteLine("The first item in the list is {0}.", ll.First.Value)
            Console.WriteLine("The last item in the list is {0}.", ll.Last.Value)

            Console.WriteLine("The LinkedList contains:")
            For Each s As String In  ll
                Console.WriteLine("   {0}", s)
            Next s 
        Else
            Console.WriteLine("The LinkedList is empty.")
        End If

    End Sub 

End Class

'This code produces the following output.
'
'The first item in the list is red.
'The last item in the list is orange.
'The LinkedList contains:
'   red
'   orange
'   yellow
'   orange

Poznámky

LinkedList<T> přijímá null jako platný Value typ odkazu a umožňuje duplicitní hodnoty.

Pokud je tato hodnota LinkedList<T> prázdná, First obsahují Lastvlastnosti null .

Tento konstruktor je operace O(1).

Platí pro

LinkedList<T>(IEnumerable<T>)

Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs

Inicializuje novou instanci LinkedList<T> třídy, která obsahuje prvky zkopírované ze zadaného IEnumerable a má dostatečnou kapacitu pro přizpůsobení počtu zkopírovaných prvků.

public:
 LinkedList(System::Collections::Generic::IEnumerable<T> ^ collection);
public LinkedList(System.Collections.Generic.IEnumerable<T> collection);
new System.Collections.Generic.LinkedList<'T> : seq<'T> -> System.Collections.Generic.LinkedList<'T>
Public Sub New (collection As IEnumerable(Of T))

Parametry

collection
IEnumerable<T>

Jejíž IEnumerable prvky jsou zkopírovány do nového LinkedList<T>.

Výjimky

collection je null.

Příklady

Příklad, který obsahuje tento konstruktor, viz LinkedList<T> třída.

Poznámky

LinkedList<T> přijímá null jako platný Value typ odkazu a umožňuje duplicitní hodnoty.

Pokud collection neobsahuje žádné prvky, je nový LinkedList<T> prázdný a First vlastnosti Last obsahují null.

Tento konstruktor je operace O(n), kde n je počet prvků v collection.

Platí pro

LinkedList<T>(SerializationInfo, StreamingContext)

Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs
Zdroj:
LinkedList.cs

Upozornění

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Inicializuje novou instanci LinkedList<T> třídy, která je serializovatelná se zadaným SerializationInfo a StreamingContext.

protected:
 LinkedList(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected LinkedList(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
protected LinkedList(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Collections.Generic.LinkedList<'T> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Generic.LinkedList<'T>
new System.Collections.Generic.LinkedList<'T> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Generic.LinkedList<'T>
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parametry

info
SerializationInfo

Objekt SerializationInfo obsahující informace potřebné k serializaci objektu LinkedList<T>.

context
StreamingContext

Objekt StreamingContext obsahující zdroj a cíl serializovaného datového proudu přidruženého k objektu LinkedList<T>.

Atributy

Poznámky

LinkedList<T> přijímá null jako platný Value typ odkazu a umožňuje duplicitní hodnoty.

Pokud je tato hodnota LinkedList<T> prázdná, First obsahují Lastvlastnosti null .

Tento konstruktor je operace O(n).

Viz také

Platí pro