C# | Removing all nodes from LinkedList<T>
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.
My Personal Notes arrow_drop_up