C# | Gets or sets the element at the specified index in StringCollection Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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: This property throws ArgumentOutOfRangeException if the index is less than zero or index is equal to or greater than Count. Below programs illustrate the use of above-discussed property: 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(); // Adding elements in StringCollection myCol.Add("A"); myCol.Add("B"); myCol.Add("C"); myCol.Add("D"); myCol.Add("E"); // Displaying objects in myCol foreach(Object obj in myCol) { Console.WriteLine(obj); } Console.WriteLine("\nAfter Item[int32] Property: \n"); // setting the value at index 2 myCol[2] = "Z"; // Displaying the elements // in the StringCollection foreach(Object obj1 in myCol) { Console.WriteLine(obj1); } } } Output: A B C D E After Item[int32] Property: A B Z D 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(); // Adding elements in StringCollection myCol.Add("Geeks"); myCol.Add("GFG"); myCol.Add("DS"); myCol.Add("Class"); myCol.Add("Noida"); // Displaying objects in myCol foreach(Object obj in myCol) { Console.WriteLine(obj); } Console.WriteLine("\nAfter Item[int32] Property: \n"); // setting the value at index 8 // this will give error as index // is greater than count myCol[8] = "C#"; // Displaying the elements // in the StringCollection foreach(Object obj1 in myCol) { Console.WriteLine(obj1); } } } Runtime Error: 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.item?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Gets or sets the element at the specified index in StringCollection K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Specialized-Namespace CSharp-Specialized-StringCollection Similar Reads 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# | 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# | 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 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# | 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# | 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 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# | 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# | 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 Finding the Start Index of the Specified Range in C# The Range Structure is introduced in C# 8.0. It represents a range that has start and end indexes. You are allowed to find the start index of the given range with the help of the Start Property provided by the Range struct.Syntax:Â Â public property Index Start { Index get(); }; Here, Index represent 2 min read Like