Create LinkedListNode containing the specified value in CSharp

Description

The following code shows how to create LinkedListNode containing the specified value.

Example


using System;/*www .ja va  2 s  .  c o m*/
using System.Collections.Generic;

public class GenericCollection  {

   public static void Main()  {
      LinkedListNode<String> lln = new LinkedListNode<String>( "Java" );
      DisplayProperties( lln );
      LinkedList<String> ll = new LinkedList<String>();

      ll.AddLast( lln );
      DisplayProperties( lln );

      ll.AddFirst( "XML" );
      ll.AddLast( "HTML" );
      DisplayProperties( lln );
   }
   public static void DisplayProperties( LinkedListNode<String> lln )  {
      if ( lln.List == null )
         Console.WriteLine("Node is not linked." );
      else
         Console.WriteLine("Node belongs to a linked list with {0} elements.", lln.List.Count );

      if ( lln.Previous == null )
         Console.WriteLine("Previous node is null." );
      else
         Console.WriteLine("Value of previous node: {0}", lln.Previous.Value );

      Console.WriteLine("Value of current node:  {0}", lln.Value );

      if ( lln.Next == null )
         Console.WriteLine("Next node is null." );
      else
         Console.WriteLine("Value of next node:     {0}", lln.Next.Value );
   }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary