C# Language Partial class and methods Partial classes inheriting from a base class

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any C# Language Question?