I know the difference between static constructor and private constructor and when to use them. But, when should one make the static constructor as private and what is the advantage of doing this?
Access modifiers are not allowed on static constructors in C#, they are (in a way) always public, meaning that the framework can always access them to perform type-specific initialization. Adding public or private to a static constructor will not compile.
A private constructor is always an instance private constructor, which is a different thing and is most commonly used when creating singletons, to prevent explicit instantiation of the class through user code.
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