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