Collection<T>.Remove(T) is used to remove the first occurrence of a specific object from the Collection<T>.
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:
Count : 5 A B C D E Count : 4 A B D E
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.
- C# | Removing first occurrence of specified value from LinkedList<T>
- C# | Remove the first occurrence of a specific object from the ArrayList
- Removing the object from the top of the Stack in C#
- C# | Index of first occurrence in StringCollection
- C# | Remove the first occurrence from the StringCollection
- C# | First occurrence in the List that matches the specified conditions
- C# | How to get the last occurrence of the element in the List that match the specified conditions
- C# | Removing the specified element from the List
- C# | Removing all the elements from the List
- C# | Removing all entries from the StringDictionary
- C# | Removing all nodes from LinkedList<T>
- C# | Removing the node at the end of LinkedList<T>
- C# | Removing the specified node from the LinkedList<T>
- C# | Removing all entries from HybridDictionary
- C# | Removing the specified key entry from HybridDictionary
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.