C# Why can I create an array of labels inside a function but not anywhere else?
问题 When I put the code: label[] label_array = {label1, label2}; Inside of a function, it works just fine. Whenever I put it anywhere else, I get the error "A field initializer cannot reference the non-static field, method, or property, file.form1.label1" Is there a different way that I can do it that will allow me to make the label array global? 回答1: You can't write that at the class level, because when the variable initialization runs those labels don't exist yet . If you want the variable at