VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-remove-all-elements-from-the-collectiont/

⇱ C# | Remove all elements from the Collection<T> - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Remove all elements from the Collection<T>

Last Updated : 11 Jul, 2025
Collection<T>.Clear method is used to remove all elements from the Collection<T>. Syntax:
public void Clear ();
Below given are some examples to understand the implementation in a better way: Example 1: Output:
Count : 5
A
B
C
D
E
Count : 0
Example 2:
Output:
Count : 4
2
3
4
5
Count : 0
Note:
  • Count is set to zero, and references to other objects from elements of the collection are also released.
  • This method is an O(n) operation, where n is Count.
Reference:
Comment

Explore