.NET支持的類型參數約束有如下五種:函數
where T : struct | T必須是一個結構類型
where T : class T必須是一個類(class)類型
where T : new() | T必需要有一個無參構造函數
where T : NameOfBaseClass | T必須繼承名爲NameOfBaseClass的類
where T : NameOfInterface | T必須實現名爲NameOfInterface的接口code
分別提供不一樣類型的泛型約束blog
能夠提供相似繼承
class MyClass<T, U> where T : class where U : struct { }