Initializing Multidimensional Arrays

A multidimensional array can also be initialized at the time that it is declared and instantiated, using an array initialization expression.
1
2
3
4
byte[,] fourRGBValues = new byte[4, 3] { {0, 255, 0},
                                         {255, 0, 0},
                                         {0, 0, 255},
                                         {255, 255, 255} };
As with one-dimensional arrays, you can leave off the array sizes after the new operator because the size of the new array can be inferred.
1
2
3
4
byte[,] fourRGBValues = new byte[,] { {0, 255, 0},
                                      {255, 0, 0},
                                      {0, 0, 255},
                                      {255, 255, 255} };
You can even leave off the new operator entirely.
1
2
3
4
byte[,] fourRGBValues = { {0, 255, 0},
                          {255, 0, 0},
                          {0, 0, 255},
                          {255, 255, 255} };