![](/img/trans.png)
[英]How to inherit multiple partial classes when all have the same base class (including the new class)?
[英]If a partial class inherits from a class then all other partial classes with the same name should also inherit the same base class?
我在我的MVC項目中有一個Model類。
public partial class Manager : Employee
{
public string Name {get;set;}
public int Age {get;set;}
}
而這個類我在同一個項目中的App_Code文件夾中。 現在我想知道我的這個類是否還需要從Employee
類繼承或不是?
public partial class Manager
{
public void SaveEmployee();
}
我必須這樣做,因為我的客戶端要我移動App_Code
文件夾中處理數據庫的所有方法。
是的,這兩個類共享相同的命名空間。
這是在多個聲明中定義的單個類,而不是兩個不同的類。 您只需要在單個聲明中定義繼承模型,例如:
public class Foo { }
//Bar extends Foo
public partial class Bar : Foo { }
public partial class Bar { }
但是,如果您嘗試以下操作,則會生成編譯器錯誤“部分聲明'Bar'不能指定不同的基類”:
public class Foo { }
public partial class Bar : Foo { }
public partial class Bar : object { }
是的,部分類的其他部分仍然是同一個類,因此它繼承自Employee。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.