public sealed class Helpers<T> where T : new()
    {          
        private static  T _instance = default(T);
        private static  object _obj = new object();
                 
        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_obj)  
                    {
                        if (_instance == null)
                        {
                            _instance = new T();
                        }
                    }
                }
                return _instance;
            }
        }
    }

解决方案 »

  1.   

    Helpers<T> where T : new()意思是声明了一个叫做Helpers<T>的泛型类,然后T的限制为必须要有一个无参构造方法。然后那个Instance属性貌似是用单例模式了吧!
      

  2.   

    恩,1楼解释的很清楚了,就是一个泛型的单件模式。使用方式:myobj a=Helpers<myobj>.Instance;
      

  3.   


    这个是不是和if (_instance == null)
    {
        _instance = new T();
    }
    这段代码有关系
    因为用的是new T()这个是无参的 所以要求必须有一个无参的构造函数?
      

  4.   


    if (_instance == null)
    {
        _instance = new T();
    }和 where T : new()相对应!