can we call static constructor from a non static constructor in .net
can we call static constructor from a non static constructor in .net??plz give some exaple if possible
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Santhosh Kumar JayaramanPosted Oct 9, 2012, 1:46 AM
Remember, static constructor will be invoked only once and it will be called for the first reference of the class. You cannot call it manually again..
From MSDN
A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
A static constructor cannot be called directly.
Sandeep Singh ShekhawatPosted Oct 9, 2012, 1:54 AM
Because static constructor calls automatically whenever any static property or any static method of that class call and its use to initilize static data for application.
For example I have two static property and one static method and calls in another class suppose sequence is
1. First Propery
2.second property
3. Method
So static constructor class only once we call first time any static property/method calls means I eeecute a program which call these in above sequnce then static constructor will call only firts property call not for second property/method means first time static class hit no matter it can be by any one of three but in my example:
1. First Propery:---constructor will call
2.second property:---constructor will not call
3. Method:---constructor will not call
Thanks
Sandeep