C# | Removing the specified element from the List Last Updated : 01 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report List.Remove(T) Method is used to remove the first occurrence of a specific object from the List. 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 duplicate elements. If the Count becomes equals to Capacity then the capacity of the List increases automatically by reallocating the internal array. The existing elements will be copied to the new array before the addition of the new element. Syntax: public bool Remove (T item); Parameter: item: Specified object which is to be remove from the List. Return Type: This method returns True if item is successfully removed. Otherwise it returns False. Note: This method returns False if item was not found in the List. Below programs illustrate how to remove the specified element from the List: Example 1: CSharp // C# program to remove the specified // element from the List<T> using System; using System.Collections.Generic; class Geeks { // Main Method public static void Main(String[] args) { // Creating a List of integers List<int> firstlist = new List<int>(); // adding elements in firstlist firstlist.Add(1); firstlist.Add(2); firstlist.Add(3); firstlist.Add(4); // Displaying elements of firstlist // by using foreach loop Console.WriteLine("Before Removing"); foreach(int element in firstlist) { Console.WriteLine(element); } // Removing 2 from the firstlist & Displaying // the remaining firstlist elements Console.WriteLine("After Removing"); firstlist.Remove(2); foreach(int element in firstlist) { Console.WriteLine(element); } } } Output: Before Removing 1 2 3 4 After Removing 1 3 4 Example 2: CSharp // C# program to remove the specified // element from the List<T> using System; using System.Collections.Generic; class Geeks { // Main Method public static void Main(String[] args) { // Creating a List of integers List<int> firstlist = new List<int>(); // adding elements in firstlist firstlist.Add(1); firstlist.Add(2); firstlist.Add(3); firstlist.Add(4); // Adding some duplicate // elements in firstlist firstlist.Add(2); firstlist.Add(4); // Displaying elements of firstlist // by using foreach loop Console.WriteLine("Before Removing"); foreach(int element in firstlist) { Console.WriteLine(element); } // Removing first occurrence of 2 // from the firstlist & Displaying // the remaining firstlist elements Console.WriteLine("After Removing"); firstlist.Remove(2); foreach(int element in firstlist) { Console.WriteLine(element); } } } Output: Before Removing 1 2 3 4 2 4 After Removing 1 3 4 2 4 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.remove?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Removing the specified element from the List K Kirti_Mangal Follow Improve Article Tags : C# CSharp-method CSharp-Generic-List CSharp-Collections-Namespace CSharp-Generic-Namespace +1 More Similar Reads C# | Removing all the elements from the List List class represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace. List class can be used to create a collection of different types like integers, strings etc. List class also provides the methods to search, sort, and manipulate lists. L 3 min read C# | Remove the specified element from a HashSet A HashSet is an unordered collection of the unique elements. It comes under System.Collections.Generic namespace. It is used in a situation where we want to prevent duplicates from being inserted in the collection. As far as performance is concerned, it is better in comparison to the list. HashSet 3 min read C# | How to remove the element from the specified index of the List List<T>.RemoveAt (Int32) Method is used to remove the element at the specified index of 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 allow 3 min read C# | Remove the element with the specified key from the Hashtable The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.Remove(Object) Method is used to remove the element with the specified key from the Hashtable. Syntax: public virt 2 min read C# | Remove the element with the specified key from a SortedList SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.Remove(Object) method is used to remove the element with the specifi 3 min read Like