C# LinkedList Count
Description
LinkedList
gets the number of nodes actually
contained in the LinkedList
Syntax
LinkedList.Count
has the following syntax.
public int Count { get; }
Example
using System;// w w w . java 2 s.c o m
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.