C# | Gets or Sets the element at the specified index in the List Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 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 T this[int index] { get; set; } Parameter: index: It is the zero-based index of the element to get or set of type System.Int32. Return Value: This property returns the element at the specified index. Exception: This method will give ArgumentOutOfRangeException if the index is less than 0 or index is equal to or greater than Count. Below are the examples to illustrate the use of List<T>.Item[Int32] Property: Example 1: CSharp // C# program to illustrate the // List.Item[32] property using System; using System.Collections.Generic; class Geeks { // Main Method public static void Main(String[] args) { // Creating a List of Strings List<String> firstlist = new List<String>(); // adding elements in firstlist firstlist.Add("A"); firstlist.Add("B"); firstlist.Add("C"); firstlist.Add("D"); firstlist.Add("E"); firstlist.Add("F"); // getting the element of // firstlist using Item property Console.WriteLine("Element at index 2: " + firstlist[2]); } } Output: Element at index 2: C Example 2: CSharp // C# program to illustrate the // List.Item[32] property using System; using System.Collections.Generic; class Geeks { // Main Method public static void Main(String[] args) { // Creating a List of String List<String> firstlist = new List<String>(); // adding elements in firstlist firstlist.Add("A"); firstlist.Add("B"); firstlist.Add("C"); firstlist.Add("D"); firstlist.Add("E"); firstlist.Add("F"); // Before setting the another // value of index 2 we will get // the element of firstlist // using Item property Console.WriteLine("Element at index 2: " + firstlist[2]); // setting the value of Element firstlist[2] = "Z"; // displaying the updated value Console.WriteLine("After Setting the new value at 2: " + firstlist[2]); } } Output: Element at index 2: C After Setting the new value at 2: Z Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.item?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Getting the value at the specified index of a SortedList object K Kirti_Mangal Follow Improve Article Tags : Misc C# CSharp-Generic-List CSharp-Collections-Namespace CSharp-Generic-Namespace +1 More Practice Tags : Misc Similar Reads C# | Get or set the element at the specified index in ArrayList ArrayList.Item[Int32] Property is used to get or set the element at the specified index in ArrayList. Syntax: public virtual object this[int index] { get; set; } Here, index is the zero-based index of the element to get or set. Return Value: It returns the element of Object type at the specified ind 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 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# | 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 C# | Getting the value at the specified index of a SortedList object SortedList.GetByIndex(Int32) Method is used to get the value at the specified index of a SortedList object. Syntax: public virtual object GetByIndex (int index); Here index is the zero-based index of the value to get. Return Value: It returns the value at the specified index of the SortedList object 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 Like