When static variable is allocated i.e. when you declare class or at the time of object creation?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.