Created
June 14, 2019 08:48
-
-
Save JoshuaMa64/de7aa1d1d22f637017d0248bf0a71152 to your computer and use it in GitHub Desktop.
C#标准单例模式实现
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 class ClassA | |
{ | |
private static ClassA _instance = null; | |
private static readonly object Padlock = new object(); | |
ClassA() { } | |
public static ClassA Instance | |
{ | |
get | |
{ | |
if (_instance == null) | |
{ | |
lock (Padlock) | |
{ | |
if (_instance == null) | |
{ | |
_instance = new ClassA(); | |
} | |
} | |
} | |
return _instance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment