- Код: Выделить всё
public class SampleIndexerClass {
private int[] innerArray = new int[10];
public int this [int Index] {
get {
if ((Index < 0) || (Index > 10))
throw new ArgumentOutOfRangeException();
return innerArray[Index];
}
set {
if ((Index < 0) || (Index > 10))
throw new ArgumentOutOfRangeException();
innerArray[Index] = value;
}
}
}
public class AppMain {
public static void Main() {
SampleIndexerClass sample = new SampleIndexerClass();
sample[0] = 1;
Console.WriteLine(sample[0]);
}
}
Подробнее здесь: http://www.dotsite.ru/Publications/Publication48.aspx