【发布时间】:2016-08-30 23:52:20
【问题描述】:
为什么i 可以调用Method?它看不到Method 的实现,只有声明,不是吗?是同时上演和拳击吗?
interface IB
{
void Method();
}
struct A : IB
{
public void Method() { Console.WriteLine("1"); }
}
class Program
{
static void Main()
{
A a;
a.Method();
IB i = a; // boxing.. and upcast?
i.Method(); // why it works? It looks like call of declaration
}
}
工作成果:
1
1
【问题讨论】:
-
@Othello.netdev,请在发送单个链接之前,简要描述该链接。
-
对不起,我已经发布了一篇很好的文章,其中界面和解释都很好。
-
首先这不是拳击的例子。这是多态的例子!
标签: c#