Csharp/CSharp Tutorial/Class/Two Dimensional Indexer
Версия от 15:31, 26 мая 2010; (обсуждение)
A two-dimensional indexer
using System;
class MyArray2D {
public MyArray2D(int r, int c) {
}
// This is the indexer for MyArray2D.
public int this[int index1, int index2] {
// This is the get accessor.
get {
return index1 + index2;
}
}
}
class MainClass {
public static void Main() {
MyArray2D myArray = new MyArray2D(3, 5);
int x;
for(int i=0; i < 6; i++) {
x = myArray[i,i];
if(x != -1) Console.Write(x + " ");
}
Console.WriteLine();
}
}
0 2 4 6 8 10