c# - a field initializer cannot reference the nonstatic field -
i have no idea why isn't working
public partial class form1 : form { public form1() { initializecomponent(); } private button[,] button = new button[3, 3]{ {button1, button2, button3 }, {button4, button5, button6 }, {button7, button8, button9 } }; private void button_click(object sender, eventargs e) { } }
i error
a field initializer cannot reference nonstatic field
on 9 buttons
a field initializer (as error states) can not reference nonstatic fields or values. button1
button9
not static. achieve same result, move array initialization in constructor of form:
private button[,] button; public form1() { initializecomponent(); button = new button[3, 3]{ {button1, button2, button3 }, {button4, button5, button6 }, {button7, button8, button9 } }; }
Comments
Post a Comment