Get or set the element at the specified index in CSharp
Description
The following code shows how to get or set the element at the specified index.
Example
using System;/*ww w . jav a 2s . c o m*/
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Demo
{
public static void Main()
{
Collection<string> myData = new Collection<string>();
myData.Add("A");
myData.Add("B");
myData.Add("C");
myData.Add("D");
Console.WriteLine(myData[2]);
myData[2] = "F";
foreach( string item in myData )
{
Console.WriteLine(item);
}
}
}
The code above generates the following result.