1

Closed

"this" Keyword

description

In most project cases, the use of "this" keyword inside a class is unregulated and some developers use it in a way an some others use in another way.

It is really important to regulate the use of the keyword. It is useful in some cases to identify a class member inside a method with many variables, but it is also useless inside a constructor, factory method or even a overloaded method.

I particullary think the use of "this" keyword is only needed on constructor calling and indexable class properties, like below:
public class MyClass
{
    public MyClass() : this(false)
    { }

    public MyClass(bool enableConfiguration)
    {
    }
}
and:
public MyClass
{
    this[int index]
    {
        get { return list.ElementAt(index); }
    }
}     
It is also a "standard" proposed in IDesign C# Coding Standard.

comments