C# | Remove from the specified index of the StringCollection Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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.RemoveAt(Int32) method is used to remove the string at the specified index of the StringCollection. Syntax: public void RemoveAt (int index); Here, index is the zero-based index of the string to remove. Exception: This method will give ArgumentOutOfRangeException if the index is less than zero or index is equal to or greater than Count. Note: This method is an O(n) operation, where n is Count. Below programs illustrate the use of StringCollection.RemoveAt(Int32) Method: Example 1: CSHARP // C# code to remove the string at the // specified index of the StringCollection using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // creating a string array named myArr String[] myArr = new String[] { "A", "B", "C", "D", "E" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); Console.WriteLine("Elements in StringCollection myCol are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); // Removing element at index 3 myCol.RemoveAt(3); Console.WriteLine("Elements in StringCollection myCol are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); } } Output: Elements in StringCollection myCol are : A B C D E Elements in StringCollection myCol are : A B C E Example 2: CSHARP // C# code to remove the string at the // specified index of the StringCollection using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // creating a string array named myArr String[] myArr = new String[] { "1", "2", "3", "4", "5" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); Console.WriteLine("Elements in StringCollection myCol are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); // Removing element at index -5 // It should raise "ArgumentOutOfRangeException" // as index is less than 0 myCol.RemoveAt(-5); Console.WriteLine("Elements in StringCollection myCol are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); } } Output: Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringcollection.removeat?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Remove from the specified index of the StringCollection S Sahil_Bansall Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Specialized-Namespace CSharp-Specialized-StringCollection +1 More Similar Reads C# | Copy StringCollection at the specified index of array 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.CopyTo(String[], Int32) method is used to copy the entire StringCollection values 3 min read C# | Remove entry with specified key from the StringDictionary StringDictionary.Remove(String) method is used to remove the entry with the specified key from the string dictionary. Syntax: public virtual void Remove (string key); Here, key is the key of the entry to remove. Exceptions: ArgumentNullException: If the key is null. NotSupportedException: If the Str 3 min read C# | Insert at the specified index in 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.Insert(Int32, String) method is used to insert a string into the StringCollection 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# | Check if the specified string is in 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.Contains(String) method is used to check whether the specified string is in the St 2 min read C# | Get or Set at specified index in 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. Properties: StringCollection accepts null as a valid value and allows duplicate elements. String co 2 min read C# | Remove all the strings 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.Clear method is used to remove all the strings from the StringCollection. Syntax: 2 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 at the specified index of 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.RemoveAt(Int32) method is used to remove the element at the speci 3 min read Like