Код: Выделить всё
using System;
class Base
{
public virtual void Foo(int x)
{
Console.WriteLine("Base.Foo(int)");
}
}
class Derived : Base
{
public override void Foo(int x)
{
Console.WriteLine("Derived.Foo(int)");
}
public void Foo(object o)
{
Console.WriteLine("Derived.Foo(object)");
}
}
public class Program
{
public static void Main()
{
Derived d = new Derived();
int i = 10;
d.Foo(i);
}
}
< /code>
А удивительный вывод: < /p>
Derived.Foo(object)
< /code>
Я ожидаю, что он выберет переопределенный метод Foo (int x) < /code>, поскольку он более конкретный. Тем не менее, компилятор C# выбирает неэнергетированную версию Foo (Object O) Какова причина такого поведения? < /P>
Подробнее здесь: https://stackoverflow.com/questions/526 ... -weirdness