LinkedList<T> 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 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
初始化为空的 LinkedList<T> 类的新实例。
public:
LinkedList();
public LinkedList ();
Public Sub New ()
示例
下面的代码示例创建并初始化 LinkedList<T> 类型的 String,添加多个节点,然后显示其内容。
#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
注解
LinkedList<T> 接受 null
作为对引用类型有效的 Value ,并允许重复值。
LinkedList<T>如果 为空,则 First 和 Last 属性包含 null
。
此构造函数是 O (1) 操作。
适用于
LinkedList<T>(IEnumerable<T>)
- 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
元素,则 new LinkedList<T> 为空,并且 First 和 Last 属性包含 null
。
此构造函数是 O (n) 操作,其中 n
是 中的 collection
元素数。
适用于
LinkedList<T>(SerializationInfo, StreamingContext)
- 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);
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)
参数
- info
- SerializationInfo
一个 SerializationInfo 对象包含序列化 LinkedList<T> 所需的信息。
- context
- StreamingContext
一个 StreamingContext 对象包含与LinkedList<T> 关联的序列化流的源和目标。
- 属性
注解
LinkedList<T> 接受 null
作为对引用类型有效的 Value ,并允许重复值。
LinkedList<T>如果 为空,则 First 和 Last 属性包含 null
。
此构造函数是 O (n) 操作。