C# LinkedList LinkedList()

Description

LinkedList LinkedList () initializes a new instance of the LinkedList class that is empty.

Syntax


public LinkedList()

Example

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


using System;//from  w ww .j  a  v  a2  s.  co m
using System.Collections;
using System.Collections.Generic;

public class GenericCollection  
{
   public static void Main()  
   {
      LinkedList<String> ll = new LinkedList<String>();
      ll.AddLast( "A" );
      ll.AddLast( "B" );
      ll.AddLast( "C" );
      ll.AddLast( "java2s.com" );

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

         foreach ( String s in ll )
            Console.WriteLine( "   {0}", s);
      }
      else  
      {
         Console.WriteLine("The LinkedList is empty.");
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack