2

Duplicate post, see: When do you use the "this" keyword?


On almost every project I worked the "This" operator is used, when i start developing i was told that it is a good practice. is this really necessary does it gives you more readability?

Community
  • 1
  • 1
Oscar Cabrero
  • 4,168
  • 8
  • 29
  • 49

1 Answers1

0

Tools like Resharper have a built in hint saying "redundant qualifier," but I disagree with it and quickly disable the rule.

I always use the this qualifier because it lets me know at a glance whether or not the reference is a property/field, or a static class ref for example:

public class MyClass {
    public int Foo { get; set; }
}

public MyClass MyRef { get; }

or

public static class MyRef {
   public static int Foo { get; set; }
}

so:

void method() {
   MyRef.Foo = 4; // might be either
}

void method() {
   this.MyRef.Foo = 4; // definitely property/field
}

Just my 2c.

-Oisin

x0n
  • 51,312
  • 7
  • 89
  • 111