语言

LinkedList<T> 构造函数

定义

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

重载

名称 说明
LinkedList<T>()

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

LinkedList<T>(IEnumerable<T>)

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

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

初始化 LinkedList<T> 使用指定 SerializationInfo 和 StreamingContext.

LinkedList<T>()

Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs

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

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

示例

下面的代码示例创建并初始化一个 LinkedList<T> 类型 String,添加多个节点,然后显示其内容。

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

注解

LinkedList<T> 接受 null 为对引用类型有效的值 Value ,并允许重复值。

如果为 LinkedList<T> 空,则 First 属性 Last 包含 null。

此构造函数是 O(1) 操作。

适用于

LinkedList<T>(IEnumerable<T>)

Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs

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

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

参数

collection
IEnumerable<T>

其 IEnumerable 元素复制到新 LinkedList<T>元素。

例外

collection 是 null。

示例

有关包含此构造函数的示例,请参阅该 LinkedList<T> 类。

注解

LinkedList<T> 接受 null 为对引用类型有效的值 Value ,并允许重复值。

如果没有 collection 元素,则新 LinkedList<T> 元素为空,并且 First 属性 Last 包含 null。

此构造函数是一个 O(n) 操作,其中 n 元素的数目 collection。

适用于

LinkedList<T>(SerializationInfo, StreamingContext)

Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs
Source:
LinkedList.cs

注意

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

初始化 LinkedList<T> 使用指定 SerializationInfo 和 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)

参数

info
SerializationInfo

一个 SerializationInfo 对象,包含序列化该 LinkedList<T>对象所需的信息。

context
StreamingContext

一个对象,包含与 <a0/> 关联的序列化流的源和目标。

特性

注解

LinkedList<T> 接受 null 为对引用类型有效的值 Value ,并允许重复值。

如果为 LinkedList<T> 空,则 First 属性 Last 包含 null。

此构造函数是 O(n) 操作。

另请参阅

适用于