Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Created February 9, 2013 17:49
Show Gist options
  • Save yetanotherchris/4746293 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4746293 to your computer and use it in GitHub Desktop.
Singleton example from Jon Skeet
public sealed class Singleton
{
Singleton()
{
}
public static Singleton Instance
{
get
{
return Nested.instance;
}
}
class Nested
{
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Nested()
{
}
internal static readonly Singleton instance = new Singleton();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment