与えられた:
interface IFoo
{
void Print(string text = "abc");
}
class Bar : IFoo
{
public void Print(string text = "def")
{
Console.WriteLine(text);
}
}
class Program
{
static void Main(string[] args)
{
Bar b = new Bar();
b.Print();
IFoo f = b as IFoo;
f.Print();
}
}
出力は次のとおりです。
def
abc
私だけですか、それともこれは少し奇妙ですか?最初は、どちらの場合も「def」を期待していました。ただし、そうなると、オプション引数の抽象メソッドは役に立たなくなります。しかし、それでも厄介なバグの良い出発点のようです。