LinkedList<T>.Clear method is used to remove the all nodes from the LinkedList<T>.
public void Clear ();
Below given are some examples to understand the implementation in a better way:
Total nodes in myList are : 5 Total nodes in myList are : 0
Total nodes in myList are : 3 Total nodes in myList are : 0
- Count is set to zero, and references to other objects from elements of the collection are also released.
- First and Last are set to null.
- This method is an O(n) operation, where n is Count.
- C# | Removing all the elements from the List
- C# | Removing the node at the end of LinkedList<T>
- C# | Removing the specified node from the LinkedList<T>
- Removing the object from the top of the Stack in C#
- C# | Removing the specified key entry from HybridDictionary
- C# | Removing all entries from HybridDictionary
- C# | Removing all entries from the StringDictionary
- C# | Removing the specified element from the List
- C# | Removing first occurrence of specified value from LinkedList<T>
- C# | Removing the node at the start of the LinkedList<T>
- C# | Removing first occurrence of object from Collection<T>
- C# | Removing a range of elements from the List
- C# | Get the number of nodes contained in LinkedList<T>
- Difference Between .NET and ASP.NET Framework
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.