我用 codacy 审查我的代码,而 codacy 跟我说
Remove the 'button1' field and declare it as a local variable in the relevant methods.
codacy 表示的行是 private Button button1;
本例中的方法 button1_Click
我的代码是(只是一个小例子,因为我的代码要大得多):
namespace WindowsFormsApp1
{
public class Form1 : Form
{
private Button button1;
public Form1()
{
InitializeComponent();
}
#region Vom Windows Form-Designer generierter Code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(349, 155);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
}
}
}
我不知道该怎么做,谁能解释我在这里做什么?问候