When static variable is allocated i.e. when you declare class or at the time of object creation?
It is compiled into the static constructor. So the first time anyone creates an object of the class or calls a static method or property on it, the initialization occurs.
Edit: when it is important to you if initialization happens before of after your own static constructor code (and some other edge cases),check the link in the comment by divo.
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