using System; public class Singleton where T : class, new() { private static T _Instance; public static T Instance { get { if (_Instance == null) _Instance = Activator.CreateInstance(); return _Instance; } } // 移除主动Singleton的功能。 // static Singleton() // { // Singleton._Instance = new T(); // } public static void CreateInstance() { if (_Instance == null) _Instance = Activator.CreateInstance(); } public static void DestroyInstance() { _Instance = null; } public static T GetInstance() { return Instance; } }