Skip to content

Instantly share code, notes, and snippets.

@arxae
Last active December 18, 2015 07:27
Show Gist options
  • Save arxae/7997c9394c9d9dc531d6 to your computer and use it in GitHub Desktop.
Save arxae/7997c9394c9d9dc531d6 to your computer and use it in GitHub Desktop.
Generic singleton pattern
// Usage: Singletone<classtype>.Instance
public sealed class Singleton<T> where T : new()
{
public static T Instance => Inner.InnerInstance;
private Singleton() { }
private class Inner
{
internal static T InnerInstance = new T();
static Inner() { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment