A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/c-sharp/c-sharp-get-the-last-node-of-the-linkedlistt/ below:

C# | Get the last node of the LinkedList<T>

C# | Get the last node of the LinkedList<T>

Last Updated : 11 Jul, 2025

LinkedList<T>.Last

property is used to get the last node of the LinkedList<T>.

Syntax:
public System.Collections.Generic.LinkedListNode Last { get; }
Return Value:

The last

LinkedListNode<T>

of the

LinkedList<T>

. Below given are some examples to understand the implementation in a better way:

Example 1: CSHARP
// C# code to get the last
// node of the LinkedList
using System;
using System.Collections;
using System.Collections.Generic;

class GFG {

    // Driver code
    public static void Main()
    {
        // Creating a LinkedList of Strings
        LinkedList<String> myList = new LinkedList<String>();

        // Adding nodes in LinkedList
        myList.AddLast("A");
        myList.AddLast("B");
        myList.AddLast("C");
        myList.AddLast("D");
        myList.AddLast("E");

        // To get the last node of the LinkedList
        if (myList.Count > 0)
            Console.WriteLine(myList.Last.Value);
        else
            Console.WriteLine("LinkedList is empty");
    }
}
Output:
E
Example 2: CSHARP
// C# code to get the last
// node of the LinkedList
using System;
using System.Collections;
using System.Collections.Generic;

class GFG {

    // Driver code
    public static void Main()
    {
        // Creating a LinkedList of Integers
        LinkedList<int> myList = new LinkedList<int>();

        // To get the last node of the LinkedList
        if (myList.Count > 0)
            Console.WriteLine(myList.Last.Value);
        else
            Console.WriteLine("LinkedList is empty");
    }
}
Output:
LinkedList is empty
Note: Reference:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4