Given:
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();
}
}
Conclusion:
def
abc
Just me or is it a little weird? Initially, I expected "def" in both cases. However, if that were the case, then the optional arguments of abstract methods would be useless. But still it seems like a good starting point for unpleasant mistakes.
source
share