顯然,擴展方法不適用於子類,還是僅僅是我?擴展方法不適用於子類?
private class Parent
{
}
private class Child
{
}
public static class Extensions
{
public static void Method(this Parent parent)
{
}
}
//Test code
var p = new Parent();
p.Method(); // <--- compiler like
var c = new Child();
c.Method(); // <--- compiler no like
UPDATE
有一個在這個問題(我要離開,以便其他有意義)一個錯字 - 我忘了讓Child
繼承Parent
。
碰巧,我真正的問題是我沒有合適的using
聲明。
(不幸的是,我無法刪除,因爲在回答太多的upvotes。)
我猜測孩子應該繼承父母嗎? (好吧,晚了幾秒鐘:o)) – hhravn 2010-09-21 10:01:55