“范型”总是让我联想到那几乎无所不能的C++ Template,可这C#的范型却让我抓狂。
C#中编译如下代码,
class A<T>
 {
        
public A()
        {
            
this.member1 = new T();
        }
        
private T member1;
 }
这代码看上去多自然啊,居然报错:
Cannot create an instance of the variable type 'T' because it does not have the new() constraint 

抓狂,不是说范型嘛,我还没说T是什么类型呢,编辑器就说does not have the new() constraint, 公然“强奸”我的意志,Bull shit。谁来拯救我这无知的人啊!


相关文章:

  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2021-04-21
  • 2021-10-10
  • 2021-06-08
猜你喜欢
  • 2021-07-07
  • 2022-12-23
  • 2021-11-25
  • 2021-12-29
  • 2021-12-14
  • 2021-08-19
  • 2021-09-12
相关资源
相似解决方案