This is how I am trying to implement my PictureBox arrays:
PictureBox[] column0 = new PictureBox[6];
PictureBox[] column1 = new PictureBox[6];
PictureBox[] column2 = new PictureBox[6];
PictureBox[] column3 = new PictureBox[6];
PictureBox[] column4 = new PictureBox[6];
PictureBox[] column5 = new PictureBox[6];
PictureBox[] column6 = new PictureBox[6];
PictureBox[][] columns =
new PictureBox[][]
{ column0, column1, column2, column3, column4, column5, column6 };
When I try to make the array of arrays, I get this error:
A field initializer cannot reference the non-static field method, or property ‘Connect_Four_Server.Server.column0’
and same errors for column1, column2, etc.
How does one declaring an array of arrays correctly in this situation?
There’s nothing wrong with the above declaration per se, but you can’t use it like that if you are declaring fields in a class. As the error states, a field initializer (in your case
columns) can’t reference other non static fields (in your casecolumn0,column1…).There are 2 approaches you can take:
Either don’t declare intermediate fields and do it all in one piece (best unless you actually need direct references to
columnX):Or put the initialization of
columnsinto the constructor: