// Port to C#
class Singleton {
public static Singleton Instance() {
if (_instance == null)//提高效率
{
lock (typeof(Singleton)) {
if (_instance == null) //防止多次创建单例对象
{
_instance = new Singleton();
}
}
}
return _instance;
}
protected Singleton() {
}
private static volatile Singleton _instance = null;
}