■
Note
The .NET Framework SDK 3.5 documentation will list indexer methods of a class or structure as a prop-
erty named
Item
. However, the Visual Studio Object Browser will show indexers as properties defined using
expected
this[]
syntax.
Indexers with Multiple Dimensions
It is also permissible to create an indexer method that takes multiple parameters. Assume you have
a custom collection that stores subitems in a 2D array. If this is the case, you may configure an
indexer method as follows:
public class SomeContainer
{
private int[,] my2DintArray = new int[10, 10];
public int this[int row, int column]
{
/* get or set value from 2D array */ }
}
C H A P T E R 1 2
■
I N D E X E R S, O P E R ATO R S, A N D P O I N T E R S
387
8849CH12.qxd 9/26/07 11:31 AM Page 387
Do'stlaringiz bilan baham: |