 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to find node in Linked List
Firstly, create a new linked list −
LinkedList<string> myList = new LinkedList<string>();
Now add some elements in the linked list −
// Add 6 elements in the linked list myList.AddLast("P"); myList.AddLast("Q"); myList.AddLast("R"); myList.AddLast("S"); myList.AddLast("T"); myList.AddLast("U"); Let’s now find a node and add a new node after that −
LinkedListNode<string> node = myList.Find("R"); myList.AddAfter(node, "ADDED"); Example
You can try to run the following code to find a node in the linked list.
using System; using System.Collections.Generic; class Program {    static void Main() {       LinkedList<string> myList = new LinkedList<string>();       // Add 6 elements in the linked list       myList.AddLast("P");       myList.AddLast("Q");       myList.AddLast("R");       myList.AddLast("S");       myList.AddLast("T");       myList.AddLast("U");       LinkedListNode<string> node = myList.Find("R");       myList.AddAfter(node, "ADDED");       foreach (var i in myList) {          Console.WriteLine(i);       }    } }  Output
P Q R ADDED S T U
Advertisements
 