.NET支持的類型參數約束有以下五種:
where T : struct | T必須是一個結構類型
where T : class | T必須是一個Class類型
where T : new() | T必須要有一個無參構造函數
where T : NameOfBaseClass | T必須繼承名為NameOfBaseClass的類
where T : NameOfInterface | T必須實現名為NameOfInterface的接口
示例:
public class Myclass<T,U> where T:class where U:struct