public static void Main()
{
Test t1 = new Test();
}
when will t1 (reference variable) will get memory, at compile time or run time.
I think it should be run time. But when I put a breakpoint at Main Method and Put a Watch for t1, it was null. So it means t1 was in memory.
Please correct me If I am wrong.
Edit: I heard Static Member Variables are assigned at compile time.
Memory is only allocated at runtime (at compile time your app isn't running).
At runtime, your t1
variable will only have a value (i.e. not null
) after the assignment has occurred, so it depends where you put your breakpoint. If you put your breakpoint on the closing brace of your Main
method and check the watch window when it's hit, you'll see what I mean.
I.e. If you put your breakpoint on the assignment line Test1 t1 = new Test1();
then that line hasn't been executed yet, so the assignment hasn't happened.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With