类型<T> where T:class的用法

public void Delete<T>(List<T> EntityList) where T : class, new()

就是说T必须是一个类(class)类型,不能是结构(structure)类型。

这是类型参数约束,.NET支持的类型参数约束有以下五种:
where T : struct                               | T必须是一个结构类型
where T : class                               
where T : new()                               | T必须要有一个无参构造函数
where T : NameOfBaseClass          | T必须继承名为NameOfBaseClass的类
where T : NameOfInterface             | T必须实现名为NameOfInterface的接口

posted @ 2014-05-17 16:27  冲向蓝天  阅读(850)  评论(0编辑  收藏  举报