Search code examples
c#coding-style

In C#, is accessing the current object's properties through this.XYZ considered poor style compared to just XYZ


Is it a simple case of just never using the this.XYZ construct?


Solution

  • It's only considered poor style if it violates your style guidelines. Sometimes using this is necessary to qualify a member variable over a local variable:

    public MyType(int arg)
    {
        this.arg = arg;
    }
    

    This problem can also be mitigated with style guidelines. For example, prefix members with "_":

    public MyType(int arg)
    {
        _arg = arg;
    }