Sergio Tapia Sergio Tapia - 7 months ago 50
C# Question

What is a singleton in C#?

Pretty straight forward question.

What is a Singleton and when should I use it?


A singleton is a class which only allows one instance of itself to be created - and gives simple, easy access to said instance. The singleton premise is a pattern across software development.

There is a C# implementation "Implementing the Singleton Pattern in C#" covering most of what you need to know - including some good advice regarding thread safety.

To be honest, It's very rare that you need to implement a singleton - in my opinion it should be one of those things you should be aware of, even if it's not used too often.