你什麼時候使用“this”關鍵字? [關閉] - When do you use the "this" keyword? [closed]

問題:

As it currently stands, this question is not a good fit for our Q&A format. 就目前而言,這個問題不適合我們的問答形式。 We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. 我們希望答案得到事實、參考或專業知識的支持,但這個問題可能會引起辯論、爭論、投票或擴展討論。 If you feel that this question can be improved and possibly reopened, visit the help center for guidance. 如果您認爲此問題可以改進並可能重新打開,請訪問幫助中心以獲取指導。
Closed 10 years ago . 10 年前關閉。
Locked . 鎖定 This question and its answers are locked because the question is off-topic but has historical significance. 此問題及其答案已鎖定,因爲該問題偏離主題但具有歷史意義。 It is not currently accepting new answers or interactions. 它目前不接受新的答案或互動。

I was curious about how other people use the this keyword.我很好奇其他人如何使用this關鍵字。 I tend to use it in constructors, but I may also use it throughout the class in other methods.我傾向於在構造函數中使用它,但我也可能在整個類中的其他方法中使用它。 Some examples:一些例子:

In a constructor:在構造函數中:

public Light(Vector v)
{
    this.dir = new Vector(v);
}

Elsewhere別處

public void SomeMethod()
{
    Vector vec = new Vector();
    double d = (vec * vec) - (this.radius * this.radius);
}

解決方案:

參考一: https://stackoom.com/question/630
參考二: When do you use the "this" keyword? [closed]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章