Created
February 9, 2013 17:49
-
-
Save yetanotherchris/4746293 to your computer and use it in GitHub Desktop.
Singleton example from Jon Skeet
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
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