Get LinkedList that the LinkedListNode belongs to in CSharp
Description
The following code shows how to get LinkedList that the LinkedListNode belongs to.
Example
using System;/*from w w w .j a va2 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" );
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 );
}
}
The code above generates the following result.