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
ArgumentOutOfRangeException if the
index is less than zero
or index is equal to
or greater than Count.
Below given are some examples to understand the implementation in a better way:
Example 1:
Output:
A
B
C
D
E
Element at index 2 is : C
Element at index 3 is : D
A
B
C
GFG
E
Example 2: