public class SingletonProvider<T> where T : new()
}
Test: public class TestClass .Instance.Write();
//另一个实现singleton的方法,不用约束的。 public static class Singleton<T> { private static T instance; public static T NewInstance() { if (instance == null) { instance = (T) Activator.CreateInstance(typeof(T), true); } return instance; } }
|
请发表评论