[英]How can I define a method with two Generic types and two type constraints?
我的方法定义是
public ActionResult _Create3<T>() where T:IMyClass, new()
但我想定义两种通用类型
public ActionResult _Create3<T, G>(G content) where T:IMyClass, new()
G型也必须使用ImyClass接口,但我不知道在哪里定义两种类型!
例如,如果可能写:
public ActionResult _Create3<T, G>(G content) where {T:IMyClass, G:IMyClass}, new()
但得到错误。
谢谢你的回答
您可以定义多个where
的多个泛型类型类似的约束:
public ActionResult _Create3<T, G>(G content) where T:IMyClass, new()
where G:IMyClass, new()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.