VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-removing-first-occurrence-of-object-from-collectiont/

⇱ C# | Removing first occurrence of object from Collection<T> - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Removing first occurrence of object from Collection<T>

Last Updated : 11 Jul, 2025
Collection<T>.Remove(T) is used to remove the first occurrence of a specific object from the Collection<T>. Syntax:
public bool Remove (T item);
Here, item is the object to remove from the Collection<T>. The value can be null for reference types. Return Value: True if item is successfully removed, otherwise, False. This method also returns False if item was not found in the original Collection<T>. Below given are some examples to understand the implementation in a better way: Example 1: Output:
Count : 5
A
B
C
D
E
Count : 4
A
B
D
E
Example 2:
Output:
Count : 5
2
3
4
4
5
Count : 4
2
3
4
5
Note: This method performs a linear search. Therefore this method is an O(n) operation, where n is Count. Reference:
Comment

Explore