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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -