When should I use the this-keyword for properties in code?
public class MyClass {
public string MyString { get; private set; }
public void MyMethod() {
OtherClass.DoStuff(MyString); // Or this.MyString?
}
}
I know that if the type and name of a property is the same you have to use this. to make it work.
public string Emailer Emailer { get { return _emailer; } }
What are the guidelines for using this. on Properties and even Methods in a class? I know it makes no difference in the compiled code. It’s all about… hold your breath… best practices.
Do whatever you and your team find most readable. Some people like to be explicit; I only specify
thiswhen I actually have to. It will make no difference to the compiled code.