The following singleton class works fine,
public class Elvis
{
private static Elvis elvis = new Elvis();
private Elvis()
{
}
public static Elvis Instance()
{
return elvis;
}
}
However, when I change return elvis; to return this.elvis, I get non-static variable this cannot be referenced from a static context. Why is this?
thisrefers to the current object instance. Astaticmethod is not contained in an object, it is contained by the class.