If a partial class inherits from a class then all other partial classes with the same name should also inherit the same base class?

前端 未结 2 1265
名媛妹妹
名媛妹妹 2020-12-16 10:04

I have a class in Model in my MVC project like this.

public partial class Manager : Employee
{
    public string Name {get;set;}
    public int Age {get;set;         


        
相关标签:
2条回答
  • 2020-12-16 10:54

    That's a single class defined across multiple declarations, not two different classes. You only need to define the inheritance model in a single declaration, e.g.:

    public class Foo { }
    
    //Bar extends Foo
    public partial class Bar : Foo { }
    
    public partial class Bar {  }
    

    However, if you were to try the following, you'd generate a compiler error of "Partial declarations of 'Bar' must not specify different base classes":

    public class Foo { }
    
    public partial class Bar : Foo { }
    
    public partial class Bar : object {  }
    
    0 讨论(0)
  • 2020-12-16 11:07

    Yes, the other part of the partial class is still the same class so it does inherit from Employee.

    0 讨论(0)
提交回复
热议问题