1
是否有任何方法將「this」傳遞給基礎構造函數?將「this」傳遞給基礎構造函數
abstract class Base<TSelf>
{
public ICollection<TSelf> List;
public Base(ICollection<TSelf> list, TSelf self)
{
List = list;
List.Add(self);
}
}
class Implementation : Base<Implementation>
{
public Implementation() : base(new List<Implementation>(), this)
{
}
}
顯然有在this
傳遞給base
的Implementation
構造一個編譯錯誤。
我也沒有看到任何方式實例list
在Base
級別。
在鑄造「TSelf」之前將'this'鑄造到'object'是解決方案! –
關於你的評論_This顯然會失敗:這不能用'where T:Base'強制執行嗎? –
@ManuelFaux:是的,會提到的。 –