Get the previous node in the LinkedList in CSharp

Description

The following code shows how to get the previous node in the LinkedList.

Example


using System;/* w w w . java2s  .  com*/
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.Previous == null )
         Console.WriteLine("Previous node is null." );
      else
         Console.WriteLine("Value of previous node: {0}", lln.Previous.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