假设我们有 2 个接口(interface):IOne
和 ITwo
,我想定义一个函数来接受同时实现这两个接口(interface)的任何类型的参数.怎么办?
最佳答案
你可以这样做:
interface IOne {void Hello();}
interface ITwo {void World();}
static void Foo<T>(T arg) where T : IOne, ITwo {
arg.Hello();
arg.World();
}
关于c# - 如何在 C# 中对变量定义中的接口(interface)求和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22123533/