Partial classes inheriting from a base class C# with Example



Partial classes inheriting from a base class C# with Example

When inheriting from any base class, only one partial class needs to have the base class specified. 
//  PartialClass1.cs 
public partial class PartialClass : BaseClass {} 
//  PartialClass2.cs 
public partial class PartialClass {} 
You can specify the same base class in more than one partial class. It will get flagged as redundant by some IDE 
tools, but it does compile correctly. 
//  PartialClass1.cs 
public partial class PartialClass : BaseClass {} 
 

//  PartialClass2.cs 
public partial class PartialClass : BaseClass {} // base class  here is  redundant 
You cannot specify different base classes in multiple partial classes, it will result in a compiler error. 
//  PartialClass1.cs 
public partial class PartialClass : BaseClass {} // compiler error 
//  PartialClass2.cs 
public partial class PartialClass : OtherBaseClass {} // compiler error 

0 Comment's

Comment Form

Submit Comment