Last active
December 18, 2015 07:27
-
-
Save arxae/7997c9394c9d9dc531d6 to your computer and use it in GitHub Desktop.
Generic singleton pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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