我的問題的一部分在this answer中回答。C#如何解析擴展方法調用?
然而,還有另一種情況:
public class A { }
public static class ExtendedA
{
public static void Ext(this A a) { }
}
public static class ExtendedB
{
public static void Ext(this A a) { }
}
public static class App
{
public static void Main()
{
A a = new A();
a.Ext();
}
}
如何在C#編譯器選擇的方法調用?
這是否編譯? – V4Vendetta
@Jamiec:是的,你可以,問題是關於擴展方法,這正是他們的工作方式。 – Ian
我想它不會編譯,因爲這個調用在兩者之間是不明確的。 – Ian