LinkedList<T> Konstruktor

Definisi

Menginisialisasi instans baru kelas LinkedList<T>.

Overload

LinkedList<T>()

Menginisialisasi instans LinkedList<T> baru kelas yang kosong.

LinkedList<T>(IEnumerable<T>)

Menginisialisasi instans LinkedList<T> baru kelas yang berisi elemen yang disalin dari yang ditentukan IEnumerable dan memiliki kapasitas yang memadai untuk mengakomodasi jumlah elemen yang disalin.

LinkedList<T>(SerializationInfo, StreamingContext)
Kedaluwarsa.

Menginisialisasi instans LinkedList<T> baru kelas yang dapat diserialisasikan dengan yang ditentukan SerializationInfo dan StreamingContext.

LinkedList<T>()

Sumber:
LinkedList.cs
Sumber:
LinkedList.cs
Sumber:
LinkedList.cs

Menginisialisasi instans LinkedList<T> baru kelas yang kosong.

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

Contoh

Contoh kode berikut membuat dan menginisialisasi LinkedList<T> jenis String, menambahkan beberapa simpul, lalu menampilkan kontennya.

#using <System.dll>

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

void main()
{
    // Create and initialize a new LinkedList.
    LinkedList< String^ > ^ ll = gcnew LinkedList< String^ >;
    ll->AddLast(L"red");
    ll->AddLast(L"orange");
    ll->AddLast(L"yellow");
    ll->AddLast(L"orange");

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

        for each (String^ s in ll)
        {
            Console::WriteLine(L"   {0}", s);
        }
    }
    else
    {
        Console::WriteLine(L"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
*/
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

Keterangan

LinkedList<T>null menerima sebagai valid Value untuk jenis referensi dan memungkinkan nilai duplikat.

LinkedList<T> Jika kosong, First properti dan Last berisi null.

Konstruktor ini adalah operasi O(1).

Berlaku untuk

LinkedList<T>(IEnumerable<T>)

Sumber:
LinkedList.cs
Sumber:
LinkedList.cs
Sumber:
LinkedList.cs

Menginisialisasi instans LinkedList<T> baru kelas yang berisi elemen yang disalin dari yang ditentukan IEnumerable dan memiliki kapasitas yang memadai untuk mengakomodasi jumlah elemen yang disalin.

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

Parameter

collection
IEnumerable<T>

Elemen IEnumerable yang disalin ke yang baru LinkedList<T>.

Pengecualian

collectionadalah null.

Contoh

Misalnya yang menyertakan konstruktor ini, lihat LinkedList<T> kelas .

Keterangan

LinkedList<T>null menerima sebagai valid Value untuk jenis referensi dan memungkinkan nilai duplikat.

Jika collection tidak memiliki elemen maka yang baru LinkedList<T> kosong, dan First properti dan Last berisi null.

Konstruktor ini adalah operasi O(n), di mana n adalah jumlah elemen dalam collection.

Berlaku untuk

LinkedList<T>(SerializationInfo, StreamingContext)

Sumber:
LinkedList.cs
Sumber:
LinkedList.cs
Sumber:
LinkedList.cs

Perhatian

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

Menginisialisasi instans LinkedList<T> baru kelas yang dapat diserialisasikan dengan yang ditentukan SerializationInfo dan 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);
[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);
new System.Collections.Generic.LinkedList<'T> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Generic.LinkedList<'T>
[<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>
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parameter

info
SerializationInfo

Objek SerializationInfo yang berisi informasi yang diperlukan untuk menserialisasikan LinkedList<T>.

context
StreamingContext

Objek StreamingContext yang berisi sumber dan tujuan aliran berseri yang terkait dengan LinkedList<T>.

Atribut

Keterangan

LinkedList<T>null menerima sebagai valid Value untuk jenis referensi dan memungkinkan nilai duplikat.

LinkedList<T> Jika kosong, First properti dan Last berisi null.

Konstruktor ini adalah operasi O(n).

Lihat juga

Berlaku untuk