C# | Get or Set at specified index in 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. Properties: StringCollection accepts null as a valid value and allows duplicate elements. String comparisons are case-sensitive. Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based. Below programs illustrate how to get or set the elements at the specified index in StringCollection: Example 1: CSHARP // C# code to get or set the element at the // specified index in 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[] { "G", "e", "E", "k", "s" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); // To get element at index 2 Console.WriteLine(myCol[2]); } } Output: E Example 2: CSHARP // C# code to get or set the element at the // specified index in 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[] { "3", "5", "7", "11", "13" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); // To get element at index 3 Console.WriteLine(myCol[3]); // Set the value at index 3 to "8" myCol[3] = "8"; // To get element at index 3 Console.WriteLine(myCol[3]); } } Output: 11 8 Comment More infoAdvertise with us Next Article C# | Get or Set at specified index in StringCollection S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Collections-Namespace CSharp-Specialized-Namespace CSharp-Specialized-StringCollection Similar Reads 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# | Gets or sets the element at the specified index in StringCollection StringCollection.Item[Int32] Property is used to get or set the element at the specified index. Syntax: public string this[int index] { get; set; } Here, index is the zero-based index of the entry to get or set. Return Value: It returns the element of String type at the specified index. Exception: T 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# | 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# | Gets or sets the value at the specified key in StringDictionary StringDictionary.Item[String] Property is used to get or set the value associated with the specified key. Syntax: public virtual string this[string key] { get; set; } Here, key is the Key of type System.String whose value is be to get or set. Return Value: This property returns the value associated 3 min read C# | Index of first occurrence 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.IndexOf(String) method is used to search the specified string which returns the ze 2 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# | Gets or Sets the element at the specified index in the List List<T>.Item[Int32] Property is used to gets or sets the element 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 value for reference types and it also allows duplicate elemen 2 min read C# | Get or set the value associated with the specified key in StringDictionary StringDictionary is a specialized collection. It is found in the System.Collections.Specialized namespace. It only allows string keys and string values. It suffers from performance problems. It implements a hash table with the key and the value strongly typed to be strings rather than objects. Below 2 min read C# | Get or set the element at specified index in Collection<T> Collection<T>.Item[Int32] property is used to get or set the element at the specified index. Syntax: public T this[int index] { get; set; } Here, index is the zero-based index of the element to get or set. Return Value: The element at the specified index. Exception: This method will give Argum 3 min read Like