interface IBar { void Hidden(); }
class Foo : IBar { public void Visible() { /*...*/ } void IBar.Hidden() { /*...*/ } }
class Program
{
static T CallHidden1<T>(T foo) where T : Foo
{
foo.Visible();
((IBar)foo).Hidden(); //Cast required
return foo;
}
static T CallHidden2<T>(T foo) where T : Foo, IBar
{
foo.Visible();
foo.Hidden(); //OK
return foo;
}
}
Run Code Online (Sandbox Code Playgroud)
是否有任何区别(CallHidden1与CallHidden2)是实际编译的代码?T:Foo和T:Foo,IBar(如果Foo实现IBar)在访问显式实现的接口成员时是否存在其他差异?