Skip to content

Instantly share code, notes, and snippets.

@RobertBonham
Created November 1, 2013 21:15
Show Gist options
  • Save RobertBonham/7272067 to your computer and use it in GitHub Desktop.
Save RobertBonham/7272067 to your computer and use it in GitHub Desktop.
Singleton done properly for 99% of needs Jon Skeet (http://pluralsight.com/training/Courses/TableOfContents/csharp-design-strategies)
public class Singleton
{
private static readonly Singleton instance = new Singleton();
// Empty static ctor forces laziness
static Singleton()
{}
private Singleton()
{
// STuff that must only happen once
Console.WriteLine("Singleton Constructor");
}
public static Singleton Instance { get { return instance; } }
public static void SayHi()
{
Console.WriteLine("Hi");
}
public void DoSomething()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment