
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Get the first node of the LinkedList in C#
To get the first node of the LinkedList, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList<String> list = new LinkedList<String>(); list.AddLast("A"); list.AddLast("B"); list.AddLast("C"); list.AddLast("D"); list.AddLast("E"); list.AddLast("F"); list.AddLast("G"); list.AddLast("H"); list.AddLast("I"); list.AddLast("J"); Console.WriteLine("Count of nodes = " + list.Count); Console.WriteLine("First Node = "+list.First.Value); list.Clear(); Console.WriteLine("Count of nodes (updated) = " + list.Count); } }
Output
This will produce the following output −
Count of nodes = 10 First Node = A Count of nodes (updated) = 0
Example
Let us see another example −
using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList<int> list = new LinkedList<int>(); list.AddLast(100); list.AddLast(200); list.AddLast(300); list.AddLast(400); list.AddLast(500); list.AddLast(600); list.AddLast(700); list.AddLast(800); list.AddLast(900); list.AddLast(1000); Console.WriteLine("Count of nodes = " + list.Count); Console.WriteLine("First Node = "+list.First.Value); Console.WriteLine("Last Node = "+list.Last.Value); list.Clear(); Console.WriteLine("Count of nodes (updated) = " + list.Count); } }
Output
This will produce the following output −
Count of nodes = 10 First Node = 100 Last Node = 1000 Count of nodes (updated) = 0
- Related Articles
- Get the last node of the LinkedList in C#
- Find the first node in LinkedList containing the specified value in C#
- Removing the node at the start of the LinkedList in C#
- Removing the specified node from the LinkedList in C#?
- Get first and last elements from Java LinkedList
- Adding new node or value at the start of LinkedList in C#
- Adding new node or value at the end of LinkedList in C#
- Find the last node in LinkedList containing the specified value in C#
- Get the number of nodes contained in LinkedList in C#
- Remove First Node of the Linked List using C++
- First and last child node of a specific node in JavaScript?
- Get SubList from LinkedList in Java
- Removing first occurrence of specified value from LinkedList in C#
- Java Program to Get the middle element of LinkedList in a single iteration
- Golang Program to Get the middle element of LinkedList in a single iteration

Advertisements