1 // cs_interface_indexers.cs
3 // Indexer on an interface:
4 public interface IMyInterface
6 // indexer declaration:
14 // Implementing the interface:
15 class IndexerClass
: IMyInterface
17 private int [] myArray
= new int[100];
18 public int this [int index
] // indexer declaration
22 // Check the index limits
23 if (index
< 0 || index
>= 100)
26 return myArray
[index
];
30 if (!(index
< 0 || index
>= 100))
31 myArray
[index
] = value;
36 public class MainClass
38 public static void Main()
40 IndexerClass b
= new IndexerClass();
41 // call the indexer to initialize the elements #3 and #5:
44 for (int i
=0; i
<=10; i
++)
46 Console
.WriteLine("Element #{0} = {1}", i
, b
[i
]);