
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Remove Specified Node from Linked List in C#
To remove the specified node from the LinkedList, the code is as follows −
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(300); list.AddLast(500); Console.WriteLine("LinkedList elements..."); foreach(int i in list) { Console.WriteLine(i); } LinkedListNode<int> val = list.FindLast(300); Console.WriteLine("Specified value = "+val.Value); list.Remove(500); Console.WriteLine("LinkedList elements...UPDATED"); foreach(int i in list) { Console.WriteLine(i); } } }
Output
This will produce the following output −
LinkedList elements... 100 200 300 400 500 300 500 Specified value = 300 LinkedList elements...UPDATED 100 200 300 400 300 500
Example
Let us see another example −
using System; using System.Collections.Generic; public class Demo { public static void Main() { LinkedList<string> list = new LinkedList<string>(); list.AddLast("Mark"); list.AddLast("David"); list.AddLast("Harry"); list.AddLast("John"); list.AddLast("Kevin"); string[] strArr = new string[5]; list.CopyTo(strArr, 0); Console.WriteLine("LinkedList elements...after copying to array"); foreach(string str in strArr) { Console.WriteLine(str); } list.Remove("Harry"); Console.WriteLine("LinkedList elements...UPDATED"); foreach(string str in list) { Console.WriteLine(str); } } }
Output
This will produce the following output −
LinkedList elements...after copying to array Mark David Harry John Kevin LinkedList elements...UPDATED Mark David John Kevin
Advertisements