-3

From within the class, how do I access a static variable explicitly? (Is the best practice to access static variable explicitly eg. using static.staticVar)

The below works

class Something {
    protected static _var1;

    public void somefunc() {
        return _var1; 
    }
}

But how do i specify it explicitly? (Is specifying explicitly recommended?)

Jiew Meng
  • 84,767
  • 185
  • 495
  • 805

1 Answers1

3

I suggest you do what is the simplest and clearest code you can. It a judgement call most of the time and if you are working with people you can ask them.

I avoid using a mutable static field if at all possible. However, in this case you can write

protected static Type s_var1; // a convention for static mutable fields

public Type somefunc() {
    return Something.s_var1; // Has to be a static field.
}
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130