class A where T:new()

  class A<T> where T:new()函数

  这是类型参数约束,where表名了对类型变量T的约束关系。where T:A 表示类型变量是继承于A的,或者是A本省。where T: new()指明了建立T的实例应该使用的构造函数。spa

  .NET支持的类型参数约束有如下五种:继承

  where T: struct                                     T必须是一个结构类型接口

  where T: class                                       T必须是一个类(class)类型,不是结构(structure)类型class

  where T: new()                                      T必需要有一个无参构造函数变量

  where T: NameOfBaseClass                     T必须继承名为NameOfBaseClass的类构造函数

  where T: NameOfInterface                      T必须实现名为NameOfInterface的接口new

相关文章
相关标签/搜索