It's easy to fill up an array using for
loop:
ulong[] chessArray = new ulong[64];
chessArray[0] = 1;
for (int i = 1; i < 64; i++)
{
chessArray[i] = 2 * chessArray[i - 1];
}
But is there a way to do it using foreach
operator? The following code won't compile:
ulong[] chessArray = new ulong[64];
chessArray[0] = 1;
foreach (int element in chessArray)
{
element = 2 * (element - 1);
}