我正在浏览一些关于 C# 4.0 的演示文稿,最后演示者发布了一个包含以下代码的测验。
using System;
class Base {
public virtual void Foo(int x = 4, int y = 5) {
Console.WriteLine("B x:{0}, y:{1}", x, y);
}
}
class Derived : Base {
public override void Foo(int y = 4, int x = 5) {
Console.WriteLine("D x:{0}, y:{1}", x, y);
}
}
class Program {
static void Main(string[] args) {
Base b = new Derived();
b.Foo(y:1,x:0);
}
}
// The output is
// D x:1, y:0
我无法弄清楚为什么会产生该输出(在没有演示者的情况下离线阅读演示文稿的问题)。我期待
D x:0, y:1
我在网上搜索了答案,但仍然找不到。有人可以解释一下吗?