第一种……
public class Singleton
{ private static Singleton _instance = null; private Singleton(){} public static Singleton CreateInstance() { if(_instance == null){
_instance = new Singleton(); } return _instance; } }另外一种
public class Singleton
{ private volatile static Singleton _instance = null; private static readonly object lockHelper = new object(); private Singleton(){} public static Singleton CreateInstance() { if(_instance == null) { lock(lockHelper) { if(_instance == null) _instance = new Singleton(); } } return _instance; } } 第三种public class Singleton{
private Singleton(){}
public static readonly Singleton instance = new Singleton(); }