Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

LinkedList.LinkedList() Constructor

Initializes a new instance of the LinkedList class that is empty.

Namespace: System.Collections.Generic
Assembly: System (in system.dll)

public:
LinkedList ()
public LinkedList ()
public function LinkedList ()
Not applicable.

LinkedList accepts a null reference (Nothing in Visual Basic) as a valid Value for reference types and allows duplicate values.

If the LinkedList is empty, the First and Last properties contain a null reference (Nothing in Visual Basic).

This constructor is an O(1) operation.

The following code example creates and initializes a LinkedList of type String, adds several nodes, and then displays its contents.

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


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.