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.

C# Concepts Posted Feb 22, 2021

You can now show your support. 😊

We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept