Two dimensional indexer
using System;
class MultiplicationTable {
private int[,] MultiplicationArray = new int[10, 10];
public int this[int x, int y] {
get {
return MultiplicationArray[x, y];
}
set {
MultiplicationArray[x, y] = value;
}
}
public MultiplicationTable() {
for (int i = 0; i < 10; i++) {
for (int y = 0; y < 10; y++) {
MultiplicationArray[i, y] = i * y;
}
}
}
}
class MultiplicationTableClient {
public static void Main(String[] args) {
MultiplicationTable MyTable = new MultiplicationTable();
Console.Write("3 x 9 is " + MyTable[3, 9]);
}
}
Related examples in the same category