I am wondering, generally in C#, the constructor concept is, base class cons should execute first, but why is that I am seeing derived class static constructor getting called and then base class cons. Could someone please explain ? :(
Static constructors initialize the class itself, which is to say that they must be called before any other static members are accessed, and before the creation of any instances of the class.
As for the ordering of calls to static constructors within a class hierarchy, you should consider that undefined. From the MSDN page on static constructors:
The user has no control on when the static constructor is executed in the program.
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