C# | Removing first occurrence of object from Collection<T> Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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: CSHARP // C# code to remove the first // occurrence of a specific object // from the Collection using System; using System.Collections.Generic; using System.Collections.ObjectModel; class GFG { // Driver code public static void Main() { // Creating a collection of strings Collection<string> myColl = new Collection<string>(); // Adding elements in Collection myColl myColl.Add("A"); myColl.Add("B"); myColl.Add("C"); myColl.Add("D"); myColl.Add("E"); // Displaying the number of elements in myColl Console.WriteLine("Count : " + myColl.Count); // Displaying the elements in myColl foreach(string str in myColl) { Console.WriteLine(str); } // Removing the first occurrence of // a specific object from the Collection myColl.Remove("C"); // Displaying the number of elements in myColl Console.WriteLine("Count : " + myColl.Count); // Displaying the elements in myColl foreach(string str in myColl) { Console.WriteLine(str); } } } Output: Count : 5 A B C D E Count : 4 A B D E Example 2: CSHARP // C# code to remove the first // occurrence of a specific object // from the Collection using System; using System.Collections.Generic; using System.Collections.ObjectModel; class GFG { // Driver code public static void Main() { // Creating a collection of ints Collection<int> myColl = new Collection<int>(); // Adding elements in Collection myColl myColl.Add(2); myColl.Add(3); myColl.Add(4); myColl.Add(4); myColl.Add(5); // Displaying the number of elements in myColl Console.WriteLine("Count : " + myColl.Count); // Displaying the elements in myColl foreach(int i in myColl) { Console.WriteLine(i); } // Removing the first occurrence of // a specific object from the Collection myColl.Remove(4); // Displaying the number of elements in myColl Console.WriteLine("Count : " + myColl.Count); // Displaying the elements in myColl foreach(int i in myColl) { Console.WriteLine(i); } } } 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: https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.collection-1.remove?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Remove all elements from the Collection S Sahil_Bansall Follow Improve Article Tags : C# CSharp-method CSharp-Collections.ObjectModel-Namespace CSharp-Collection-Class Similar Reads C# | Removing first occurrence of specified value from LinkedList<T> Remove(T) method is used to remove the first occurrence of the specified value from the LinkedList<T>. Syntax: public bool Remove (T value); Here, value is the value to remove from the LinkedList<T>. Return Value: This method returns True if the element containing value is successfully r 3 min read C# | Remove the first occurrence of a specific object from the ArrayList ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Remove(Object) method is used to remove the first occurrence of a 3 min read C# | Remove all elements from the Collection<T> 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: CSHARP // C# code to remove all // elements from the Collection using System; using S 2 min read C# | Remove the first occurrence from the StringCollection StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.Remove(String) method is used to remove the first occurrence of a specific string 3 min read C# | Removing a range of elements from the List List<T>.RemoveRange(Int32, Int32) Method is used to remove a range of elements from the List<T>. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot.List class can accept null as a valid value for reference types and it also allows dup 3 min read C# | Searching the index of specified object in Collection<T> Collection<T>.IndexOf(T) method is used to search for the specified object and returns the zero-based index of the first occurrence within the entire Collection<T>. Syntax: public int IndexOf (T item); Here, item is the object to locate in the List<T>. The value can be null for ref 2 min read Like