// Singleton pattern in C# (see DESIGN PATTERNS) // a class that manages a sole instance of itself and // does not allow additional instances to be created // other classes obtain a reference to the Singleton type // by calling the GetInstance() method public sealed class Singleton { static readonly Singleton instance=new Singleton(); // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit, which just // means that it tries to do lazy instantiation // (constructs itself only if really used) static Singleton() { } private Singleton() { } public static Singleton GetInstance() { return instance; } }