I suggest that if you use this. To enhance what you mean by instance members, the equivalent in a static member should be to use ClassName.
But stylistically, why add code that doesn't change the meaning?
edit to add various explanations:
My last sentence above can be illustrated by the following examples:
class Example1 { public int J { get; set; } public Example1() { J = 0; }
this. in InstanceMethodLong does not change the value compared to InstanceMethodShort .
Statically:
class Example2 { public static int K { get; set; } static Example2() { K = 0; }
Example2. in StaticMethodLong does not change the value compared to StaticMethodShort .
In both cases, adding a qualifier leads to the same CIL, to the same behavior, and is more a source for writing, reading, and understanding. Stylistically - and I gladly agree that this is a code style issue - I see no reason for it to be there.
With underscores, the situation is slightly different:
class Example3 { int _j; public int J { get { return _j; } set { _j = value; // and do something else, // to justify not using an auto-property } } public Example3() { J = 0; } public int MethodWithParameter(int j) { // Now there is a *difference* between return j; // and return _j; } }
Here, in MethodWithParameter , there is a difference between the _j and j reference - so we intentionally and explicitly express different meanings. Itβs true that the compiler doesnβt care what we call the names of our variables, but it doesnβt matter what variables we mean! Thus, in the body of MethodWithParameter using or not using underscores is not just stylistic, but also semantic. This is not the problem we are addressing in this matter.
Aakashm
source share