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

相關文章
相關標籤/搜索