Created
February 17, 2015 15:41
-
-
Save MechMK1/ca08d51fc936988b7b8a to your computer and use it in GitHub Desktop.
C# Singletons
This file contains hidden or 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
| class Singleton | |
| { | |
| //Private static field to hold the instance | |
| private static Singleton _singleton = null; | |
| // Getter for the instance | |
| public static Singleton Instance | |
| { | |
| get | |
| { | |
| //Return the instance if not null (see ??-operator) | |
| return _singleton ?? ( | |
| _singleton = new Singleton() //Create instance, assign and return it | |
| ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment