C# | Copy the elements of a string array to the end 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.AddRange(String[]) method is used to copy the elements of a string array to the end of the StringCollection. Syntax: public void AddRange (string[] value); Here, string[] value is an array of strings which will be added to the end of the StringCollection. The array itself can not be null but it can contain elements that are null. Exception: This method will give ArgumentNullException if value is null. Note: StringCollection accepts null as a valid value and allows duplicate elements. If the StringCollection can accommodate the new elements without increasing the capacity, this method is an O(n) operation, where n is the number of elements to be added. If the capacity needs to be increased to accommodate the new elements, this method becomes an O(n + m) operation, where n is the number of elements to be added and m is Count. Below programs illustrate the use of StringCollection.AddRange(String[]) Method: Example 1: CSHARP // C# code to copy the elements // of a string array to the end // 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); // Displaying elements in StringCollection foreach(Object obj in myCol) { Console.WriteLine("{0}", obj); } } } Output: A B C D E Example 2: CSHARP // C# code to copy the elements // of a string array to the end // 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[] { "2", "3", "4", "5", "6" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); // Displaying elements in StringCollection foreach(Object obj in myCol) { Console.WriteLine("{0}", obj); } } } Output: 2 3 4 5 6 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringcollection.addrange?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Copy the elements of a string array to the end 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# | Add a string to the end of 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.Add(String) Method is used to add a string to the end of the StringCollection. Syn 2 min read 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# | Adding the elements of the specified collection to the end of the List List<T>.AddRange(IEnumerable<T>) Method is used to add the elements of the specified collection to the end 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 refer 3 min read C# | Remove from the specified index of 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.RemoveAt(Int32) method is used to remove the string at the specified index of the 3 min read C# | How to insert the elements of a collection into the List at the specified index List<T>.InsertRange(Int32, IEnumerable<T>) Method is used to insert the elements of a collection into the List<T> at the specified index. 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 3 min read Like