Initializes a new instance of the LinkedList class that is empty. : LinkedList « Collections Data Structure « C# / C Sharp






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

 
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.");
      }
   }
}

   
  








Related examples in the same category

1.Create LinkedList Generic Class with a string array
2.Add the word 'today' to the beginning of the linked list
3.Move the first node to be the last node
4.Change the last node be 'yesterday'
5.Move the last node to be the first node
6.Indicate, by using parentheisis, the last occurence of 'the'
7.LinkedListNode(T) Class represents a node in a LinkedList. This class cannot be inherited.