相关疑难解决方法(0)

你什么时候使用"this"关键字?

我很好奇其他人如何使用this关键字.我倾向于在构造函数中使用它,但我也可以在其他方法中使用它.一些例子:

在构造函数中:

public Light(Vector v)
{
    this.dir = new Vector(v);
}
Run Code Online (Sandbox Code Playgroud)

别处

public void SomeMethod()
{
    Vector vec = new Vector();
    double d = (vec * vec) - (this.radius * this.radius);
}
Run Code Online (Sandbox Code Playgroud)

c# coding-style this

248
推荐指数
11
解决办法
19万
查看次数

标签 统计

c# ×1

coding-style ×1

this ×1