Hi all,
I found this example in the help and thought this is great. But I can not
figure out how to
iterate thru the array and print out the values in the array.
Do I use a foreach (I tried could not get that to work) or a for loop (same
result)
my test harness below works so I know I am getting values into the grid,
which is a two
dimensioned array with an indexer[char,int]
a little code example please
thanks
grs
public static void Main()
{
Grid aGrid = new Grid();
aGrid['A',1] = 1;
Console.WriteLine(aGrid['A',1].ToString());
*** so here how do I loop thru the array
=======================
class Grid
{
const int NumRows = 26;
const int NumCols = 10;
int[,] cells = new int[NumRows, NumCols];
public int this[char c, int col]
{
get
{
c = Char.ToUpper(c);
if (c < 'A' || c > 'Z')
{
throw new ArgumentException();
}
if (col < 0 || col >= NumCols)
{
throw new IndexOutOfRangeException();
}
return cells[c - 'A', col];
}
set
{
c = Char.ToUpper(c);
if (c < 'A' || c > 'Z')
{
throw new ArgumentException();
}
if (col < 0 || col >= NumCols)
{
throw new IndexOutOfRangeException();
}
cells[c - 'A', col] = value;
}
}
}