C# LinkedListNode LinkedListNode
Description
LinkedListNode
initializes
a new instance of the LinkedListNode
Syntax
public LinkedListNode(
T value
)
Parameters
value
- The value to contain in the LinkedListNode.
Example
The following code example creates a LinkedListNode, adds it to a LinkedList, and tracks the values of its properties as the LinkedList changes.
using System;// w w w .jav a 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.