C# 泛型 WHERE 约束
2017-08-17 09:44
295 查看
WHERE
子句用于指定对下列类型的约束:这些类型可用作泛型声明中定义的类型形参的实参。
public
class
MyGenericClass<T>
where
T:IComparable
{ } T实现IComparable 接口
public void Request<T>(List<T> EntityList) where T : class
public
class
MyGenericClass<T>
where
T :
IComparable,
new()
class
MyClass<T,
U>
where
T :
class
where
U :
struct
.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
MyGenericClass<T>
where
T:IComparable
{ } T实现IComparable 接口
public void Request<T>(List<T> EntityList) where T : class
public
class
MyGenericClass<T>
where
T :
IComparable,
new()
class
MyClass<T,
U>
where
T :
class
where
U :
struct
.NET支持的类型参数约束有以下五种:
where T : struct | T必须是一个结构类型
where T : class | T必须是一个Class类型
where T : new() | T必须要有一个无参构造函数
where T : NameOfBaseClass | T必须继承名为NameOfBaseClass的类
where T : NameOfInterface | T必须实现名为NameOfInterface的接口
相关文章推荐
- C#中的where泛型约束中的new()使用(转)
- C# 泛型约束 xxx Where T:约束(二)
- C#中的where泛型约束中的new()
- C#中的where泛型约束中的new()构造函数约束
- C#中的where泛型约束
- C#中的where泛型约束
- C# 泛型方法Where 约束
- c#中的WHERE语句 ——where(泛型类型约束)
- c# where(泛型类型约束)
- C#中的where泛型约束中的new()构造函数约束
- C#中的where泛型约束【转】
- c# 泛型类型参数T的约束where
- where(泛型类型约束)(C# 参考)
- 关于C#中泛型类型参数约束(where T : class)
- c# 泛型T类型参数T的约束where
- C# 泛型约束 xxx<T> Where T:约束(一)
- C#中的where泛型约束
- C# 泛型类型约束 where
- c#泛型类型的约束条件where
- 关于C#中泛型类型参数约束(where T : class)