using System; class MyClass { public string value0; public string value1; public string value2; public string this[int index] { set { switch (index) { case 0: value0 = value; break; case 1: value1 = value; break; case 2: value2 = value; break; } } get { switch (index) { case 0: return value0; case 1: return value1; case 2: return value2; default: return ""; } } } } class MainClass { static void Main() { MyClass myObject = new MyClass(); myObject.value0 = "0"; myObject.value1 = "1"; myObject.value2 = "2"; Console.WriteLine("{0}, {1}, {2}", myObject[0], myObject[1], myObject[2]); } }
0, 1, 2