/// <summary>
    /// 单例模式
    /// </summary>
    public sealed class Singleton<T> where T:new()
    {
        private Singleton() { }//防止new对象
        public static T Instance
        {
            get { return SingletonCreator.instance; }//延迟加载
        }
        internal class SingletonCreator
        {
            static SingletonCreator() { }
            internal static readonly T instance = new T();
        }
    }


调用方法  

你的类  obj=Singleton<你的类>.Instance;

相关文章:

  • 2022-12-23
  • 2021-08-08
  • 2022-03-08
  • 2022-12-23
  • 2021-10-03
  • 2021-12-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
相关资源
相似解决方案