【发布时间】:2010-09-08 00:31:01
【问题描述】:
在 C# 中,可以定义具有两个接口限制的方法参数。这是有界的。例如。
interface IA
{
int A {get;}
}
interface IB
{
int B {get;}
}
void Foo<T>(T param1) where T: IA, IB {}
所以两个接口,方法Foo的第一个参数(param1)应该实现这两个接口。
但这真的有用吗? AFAIK 不可能在 C# 中将对象强制转换为多个接口?当然一个类可以实现两个接口。
【问题讨论】:
-
@RobertMacLean 不是重复的。这是相反的方式
标签: c# generics parameters interface