- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LinkedList Clear() Method in C#
Use the Clear() method to clear a LinkedList. This will remove all the nodes from the LinkedList.
Let’s say the following is our LinkedList −
int [] num = {30, 65, 80, 95, 110, 135}; LinkedList<int> list = new LinkedList<int>(num);
To clear the LinkedList.
list.Clear();
Example
using System; using System.Collections.Generic; class Demo { static void Main() { int [] num = {30, 65, 80, 95, 110, 135}; LinkedList<int> list = new LinkedList<int>(num); foreach (var n in list) { Console.WriteLine(n); } // clear list.Clear(); Console.WriteLine("No node in the LinkedList now..."); foreach (var n in list) { Console.WriteLine(n); } } }
Output
30 65 80 95 110 135 No node in the LinkedList now...
Advertisements