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
C# program to remove the first occurrence of a node in a Linked List
The following is our LinkedList list with nodes.
string [] students = {"Katie","Jennifer","Amy","Vera"};
LinkedList<string> list = new LinkedList<string>(students);
Now let us remove a node with the string element “Vera”.
For that, use Remove() method.
list.Remove("Vera");
Example
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
string [] students = {"Katie","Jennifer","Amy","Vera"};
LinkedList<string> list = new LinkedList<string>(students);
foreach (var stu in list) {
Console.WriteLine(stu);
}
// removing a node
list.Remove("Vera");
Console.WriteLine("LinkedList after removing a node...");
foreach (var stu in list) {
Console.WriteLine(stu);
}
}
}
Output
Katie Jennifer Amy Vera LinkedList after removing a node... Katie Jennifer Amy
Advertisements