What is the difference between a Static Constructor and a Singleton?

  • Static constructors are run once for a type at an unknown time before any of the static members are called.
  • Adding a static constructor doesn't stop the class from being initialized, it is just that the members which are desired to be instantiated only once are placed inside a static constructor (for example a HttpClient)
  • A Singleton class has a private constructor by design, which stops it from being instantiated and hence only a single instance of the type can be circulated at any time.
  • Static constructors are run once for a type at an unknown time before any of the static members are called.
  • Adding a static constructor doesn’t stop the class from being initialized, it is just that the members which are desired to be instantiated only once are placed inside a static constructor (for example a HttpClient)
  • A Singleton class has a private constructor by design, which stops it from being instantiated and hence only a single instance of the type can be circulated at any time.
Default image
Sriram Mannava

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity.

Leave a Reply

Your email address will not be published.