
- 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
How to implement Traversal in Singly Linked List using C#?
Set a linkelist collection −
var list = new LinkedList<string>();
Now, add elements −
list.AddLast("One"); list.AddLast("Two"); list.AddLast("Four");
Now, let us add new elements in the already created LinkedList −
LinkedListNode<String> node = list.Find("Four"); list.AddBefore(node, "Three"); list.AddAfter(node, "Five");
Let us now see how to traverse through the nodes in a Singly Linked List −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var list = new LinkedList < string > (); list.AddLast("One"); list.AddLast("Two"); list.AddLast("Four"); Console.WriteLine("Travering..."); foreach(var res in list) { Console.WriteLine(res); } LinkedListNode < String > node = list.Find("Four"); list.AddBefore(node, "Three"); list.AddAfter(node, "Five"); Console.WriteLine("Travering after adding new elements..."); foreach(var res in list) { Console.WriteLine(res); } } }
- Related Articles
- C++ Program to Implement Singly Linked List
- C++ Program to Implement Circular Singly Linked List
- C++ Program to Implement Sorted Singly Linked List
- C++ Program to Implement Sorted Circularly Singly Linked List
- Singly LinkedList Traversal using C#
- Convert singly linked list into circular linked list in C++
- Convert singly linked list into XOR linked list in C++
- C++ Program to Implement Queue using Linked List
- C++ Program to Implement Stack using linked list
- Search an element in the given singly Linked List using C++
- Binary Search on Singly Linked List in C++
- C++ Program to Implement Hash Tables chaining with Singly Linked Lists
- Find middle of singly linked list Recursively in C++
- Recursive insertion and traversal linked list in C++
- Difference between Singly linked list and Doubly linked list in Java

Advertisements