In a rather limiting context I need to reference a static class field from a constructor that has a variable named with the same name as the static field. Here is an example to illustrate, which also includes a non-static field to highlight the fact that for non-static fields one can use “this” to reference the class-field:
public class Example () {
private static DateTime firstInstance;
private static DateTime referenceInstance;
private String Name;
static Example() {
first=DateTime.Now;
}
public Example(String Name, DateTime referenceInstance) {
this.Name=Name;
referenceInstance=referenceInstance;
}
}
How can one access the “referenceInstance” static field without the “this” keyword as one does with “Name”? In a perfect world I would just refactor either the class variable or the constrictor variable to have a different identifier, however for a rather technical reason (printing documentation) neither can be changed here.
Thanks.
Fully qualify the static variable name in the constructor.