你能透露一下这个“这个”的身份吗?

时间:2015-01-04 22:35:15

标签: c#

在我添加"按钮控制后#34;在Form1中,我自动在Form1.Desiner.cs中获得了这些代码。

    this.button1.Location = new System.Drawing.Point(78, 49);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(113, 41);
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.UseVisualStyleBackColor = true;
    this.button1.Click += new System.EventHandler(this.button1_Click);

现在我开始想知道"这个"的真实身份是什么。 所以我试着用

替换它(第4行)
WindowsFormsApplication1.Form1.button1.TabIndex = 0;

System.Windows.Forms.Button Form1.button1.TabIndex = 0;

但是我收到了以下错误消息,我不明白。

An object reference is required for the non-static field, Form1.Desiner.cs method, or property 'WindowsFormsApplication1.Form1.button1'

所以请告诉我如何更换"这个"合适的方式? (当然,它的目的是为了理解)

1 个答案:

答案 0 :(得分:3)

this是对当前对象的引用。

假设this现在正常运行,并且this不能消除其他标识符(如本地变量或参数)的歧义,您可以简单地删除{ {1}} ,代码仍应有效。

this

这是否是个好主意是另一回事。