Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Clear a Linked List in C#
Clear a LinkedList using Clear() method.
Let us first set a LinkedList.
string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"};
LinkedList<string> list = new LinkedList<string>(employees);
Now, let us clear the LinkedList.
list.Clear();
Let us see the complete code.
Example
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"};
LinkedList<string>list = new LinkedList<string>(employees);
foreach (var emp in list) {
Console.WriteLine(emp);
}
// clearing list
list.Clear();
Console.WriteLine("LinkedList after removing the nodes (empty list)...");
foreach (var emp in list) {
Console.WriteLine(emp);
}
}
}
Output
Patrick Robert John Jacob Jamie LinkedList after removing the nodes (empty list)...
Advertisements
