LinkedList(T) コンストラクター (System.Collections.Generic)

ビューの切り替え:
スクリプトなし
.NET Framework クラス ライブラリ
LinkedList<T> コンストラクター
この記事は翻訳者によって翻訳されたものです。 このページおよび元の英語コンテンツを同時に表示させるには、[ライトウェイト] に切り替えます。

LinkedList<T> クラスの新しい空のインスタンスを初期化します。

名前空間:  System.Collections.Generic
アセンブリ:  System (System.dll 内)
構文

Visual Basic
Public Sub New
C#
public LinkedList()
Visual C++
public:
LinkedList()
F#
new : unit -> LinkedList
解説

LinkedList<T> は、null を参照型に対して有効な Value として受け取り、値の重複を許可します。

LinkedList<T> が空の場合、First プロパティと Last プロパティには null が格納されます。

このコンストラクターは O(1) 操作です。


String 型の LinkedList<T> を作成および初期化し、いくつかのノードを追加し、その内容を表示するコード例を次に示します。

Visual Basic

Imports System
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 <null>.
'The last item in the list is orange.
'The LinkedList contains:
'   red
'   orange
'   yellow
'   orange



C#

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 item in the list is {0}.", ll.First.Value );
         Console.WriteLine( "The 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
*/


Visual C++

#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
*/



バージョン情報

.NET Framework

サポート対象: 4、3.5、3.0、2.0

.NET Framework Client Profile

サポート対象: 4、3.5 SP1

サポート対象:
プラットフォーム

Windows 7, Windows Vista SP1 以降, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core はサポート対象外), Windows Server 2008 R2 (SP1 以降で Server Core をサポート), Windows Server 2003 SP2

.NET Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
参照

参照