in some sites it's mention ,we can create one static constructor within a class .
and in some other sites it mention more than one staic constructor.
which is correct???
in some sites it's mention ,we can create one static constructor within a class .
and in some other sites it mention more than one staic constructor.
which is correct???
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Oct 9, 2012, 12:34 AM EDT
When we call any property/method of static class we can not decide which constructor call only default constructor is called so what's need of other constructor.
Static constructor use to intilize static member of class and static member have only one value in a session in IIS so what's purpose of another static constructor.
So in short we can define only one static constructor in an single static class.
Thanks
Sandeep
Kunal VaishyaRank #990 · 2K reputationPosted Oct 8, 2012, 10:23 PM EDT
you can create as per requirement but using overload methods concept using passes different parameters.
VulpesRank #55 · 29.2K reputationPosted Oct 9, 2012, 1:17 AM EDT
A class or struct can have (at most) one static constructor.
This cannot have any parameters or an access modifier and cannot be called directly - it is called automatically by the system before any other static member is accessed or instance constructor is invoked.