C# LinkedList LinkedList()
Description
LinkedList
initializes
a new instance of the LinkedList
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.