LinkedList<T> Konstruktorer

Definition

Initierar en ny instans av LinkedList<T> klassen.

Överlagringar

Name Description
LinkedList<T>()

Initierar en ny instans av LinkedList<T> klassen som är tom.

LinkedList<T>(IEnumerable<T>)

Initierar en ny instans av LinkedList<T> klassen som innehåller element som kopierats från den angivna IEnumerable och har tillräcklig kapacitet för att hantera antalet kopierade element.

LinkedList<T>(SerializationInfo, StreamingContext)

Initierar en ny instans av LinkedList<T> klassen som kan serialiseras med angiven SerializationInfo och StreamingContext.

LinkedList<T>()

Initierar en ny instans av LinkedList<T> klassen som är tom.

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

Exempel

I följande kodexempel skapas och initieras en LinkedList<T> av typen String, lägger till flera noder och visar sedan dess innehåll.

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

Kommentarer

LinkedList<T> null accepterar som giltigt Value för referenstyper och tillåter duplicerade värden.

Om är LinkedList<T> tom First innehåller nullegenskaperna och Last .

Den här konstruktorn är en O(1)-åtgärd.

Gäller för

LinkedList<T>(IEnumerable<T>)

Initierar en ny instans av LinkedList<T> klassen som innehåller element som kopierats från den angivna IEnumerable och har tillräcklig kapacitet för att hantera antalet kopierade element.

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))

Parametrar

collection
IEnumerable<T>

Vars IEnumerable element kopieras till den nya LinkedList<T>.

Undantag

collection är null.

Exempel

Ett exempel som innehåller den här konstruktorn finns i LinkedList<T> klassen .

Kommentarer

LinkedList<T> null accepterar som giltigt Value för referenstyper och tillåter duplicerade värden.

Om collection det inte finns några element är den nya LinkedList<T> tom och First egenskaperna och Last innehåller null.

Den här konstruktorn är en O(n)-åtgärd, där n är antalet element i collection.

Gäller för

LinkedList<T>(SerializationInfo, StreamingContext)

Initierar en ny instans av LinkedList<T> klassen som kan serialiseras med angiven SerializationInfo och StreamingContext.

protected:
 LinkedList(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected LinkedList(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
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)

Parametrar

info
SerializationInfo

Ett SerializationInfo objekt som innehåller den information som krävs för att serialisera LinkedList<T>.

context
StreamingContext

Ett StreamingContext objekt som innehåller källan och målet för den serialiserade dataström som är associerad med LinkedList<T>.

Kommentarer

LinkedList<T> null accepterar som giltigt Value för referenstyper och tillåter duplicerade värden.

Om är LinkedList<T> tom First innehåller nullegenskaperna och Last .

Den här konstruktorn är en O(n)-åtgärd.

Se även

Gäller för