Is `this` keyword optional when accessing members in C#?

前端 未结 4 635
梦毁少年i
梦毁少年i 2021-01-18 01:58

I notice that if you have a private member in a class, you can access it in the class methods by just referring to it\'s name. You do not need to say this.memberName

4条回答
  •  梦毁少年i
    2021-01-18 02:57

    Yes, it's optional. The only times you'd have to use it are when you have a local variable that hides a member variable, or you want to refer to an indexed property (aka indexer).

提交回复
热议问题