Skip to content

Instantly share code, notes, and snippets.

@JoshuaMa64
Created June 14, 2019 08:48
Show Gist options
  • Save JoshuaMa64/de7aa1d1d22f637017d0248bf0a71152 to your computer and use it in GitHub Desktop.
Save JoshuaMa64/de7aa1d1d22f637017d0248bf0a71152 to your computer and use it in GitHub Desktop.
C#标准单例模式实现
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