C# LinkedList Last
Description
LinkedList
gets the last node of the LinkedList
Syntax
LinkedList.Last
has the following syntax.
public LinkedListNode<T> Last { get; }
Example
using System;// w ww .ja v a 2 s .c om
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.