I’m just curious how this works:
In my class Form1.cs I have declared an object static:
public static Class1 class1;
This is how the constructor of Class1 looks like:
public Class1()
{
Form1.class1 = null;
}
I expected to get a null reference exception in MS VS 2010
class1 = new Class1();
class1.showMSG();
But instead it just executes showMSG() (showMSG is not static) like I’ve never set the reference to class1 to null.
Any thoughts on this?
Class1’s constructor sets
But when you execute
the assignment to
class1(which is the sameclass1) happens after the constructor executes. SoForm1.class1now has a value.