你要干嘛?
方法返回类型是void,你还return new T()?

解决方案 »

  1.   

    除了上面说的返回的问题,想 new T() 就必须约束T有公开的无参构造:void GetEntity<T>() where T : new()
      

  2.   

    没看懂想要干嘛
    如果是要返回T,那就要说明T是不是class,那就应该是类似下面的代码T GetEntity<T>()
       where T:new()
    {
    if (this.Value == null)
    {
    this.Value = new T();
    }
    return this.Value;
    } 如果是要返回默认值,那就应该是下面类似的代码
    T Get<T>()
    {
           return default(T);
    }
      

  3.   

    T GetEntity<T>() where T : new()
            {
                return (T)(Value ?? (Value=new T()));
            }
      

  4.   

    代码问题太多,直接写一个给你吧:
    T GetEntity<T>() : where T : class, new()
     {
     if (this.Value == null)
     this.Value = new T();
     return new T();
     } 
      

  5.   

    T GetEntity<T>() where T : class, new()
     {
     if (this.Value == null)
     this.Value = new T();
     return this.Value;
     }