using System;
public class A {
private double d, e, f;
public A(double v){
d = e = f = v;
}
public double this [int i]{
get {
switch (i){
case 1: {return d;}
case 2: {return e;}
case 3: {return f;}
default: throw new Exception("Error");
}
}
set {
switch (i){
case 1: {d = value; break;}
case 2: {e = value; break;}
case 3: {f = value; break;}
default: throw new Exception("Error");
}
}
}
public override string ToString(){
return "A: " + d + ", " + e + ", " + f;
}
} | |
Three private instance variables
... all initialized to the same value
anAObject[1] returns d
anAObject[2] returns e
anAObject[3] returns f
anAObject[1] = ... assigns d
anAObject[2] = ... assigns e
anAObject[3] = ... assigns f
|