
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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...
- Related Articles
- Clear LinkedList in Java
- LinkedList AddFirst method in C#
- LinkedList AddAfter method in C#
- LinkedList Remove method in C#
- LinkedList RemoveFirst() Method in C#
- LinkedList RemoveLast() Method in C#
- LinkedList Contains Method in C#
- LinkedList AddLast method in C#
- LinkedList AddBefore method in C#
- NavigableMap clear() Method in Java
- ArrayBlockingQueue clear() Method in Java
- Java IdentityHashMap clear() method
- The clear() method of AbstractSequentialList in Java
- The clear() method of CopyOnWriteArrayListin Java
- HTML DOM Local Storage clear() method

Advertisements