我正在做一个窗口表格申请。当我查看文件Form1.Designer.cs时,在我看到的自动生成的代码中
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);这个告诉我们什么?在c#中可以使用多少种方式?
发布于 2013-02-24 14:50:29
它引用类的当前实例。如果您正在使用像ReSharper这样的工具,它有时会被认为是多余的。
public class Test
{
private string testVariable;
public Test(string testVariable)
{
this.testVariable = testVariable;
}
}在此上下文中,this.testVariable引用类中的私有字符串,而不是通过构造函数传入的testVariable。
http://msdn.microsoft.com/en-gb/library/dk1507sz(v=vs.71).aspx
发布于 2013-02-24 14:52:27
this 关键字引用类的当前实例,因此在本例中是正在加载的Form1实例。
至于你为什么要使用它,它可以帮助区分变量。
private string bar;
private void Foo(string bar)
{
this.bar = bar;
}(尽管对于上面的代码,许多人会认为私有酒吧应该是_bar)
有关这的更多信息
发布于 2013-02-24 14:52:18
this关键字引用class的当前实例,并用作扩展方法的第一个参数的修饰符。
public Employee(string name, string alias)
{
// Use this to qualify the fields, name and alias:
this.name = name;
this.alias = alias;
}https://stackoverflow.com/questions/15052886
复制相似问题