Using System;namespace Indexer {class Program {static void Main (string[] args) {Phone A1 = NE W Phone ("Xiaomi", 3000); Console.WriteLine (A1[0]); Console.WriteLine (A1[1]); Console.WriteLine (A1[3]); Console.WriteLine ("-----------------------------------------"); A1[0] = "Huawei"; A1[1] = "5000"; A1[3] = "Nokia"; Console.WriteLine (A1[0]); Console.WriteLine (A1[1]); Console.WriteLine (A1[3]); Console.readkey (); }} public class Phone {public string name; public int price; Public Phone (string name, int eag) {this.name = name; This.price = EAG; public String This[int Index] {get {if (index = = 0) {return this.name; } else if (index = = 1) { Return convert.tostring (This.price); } else {return ' cannot get an index that does not exist: ' + index; }} set {if (index = = 0) {this.name = Value } else if (index = = 1) {This.price = Convert.ToInt32 (value); } else {Console.WriteLine ("Cannot set an index that does not exist:" + index); } } } }}
C # Indexer