public class SingletonProvider<T> where T : new()

}

 Test:
c#单态模式与泛型结合的使用方法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;
        }
    }

相关文章: