C# Language Partial class and methods

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 Insert
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Partial classes provides us an option to split classes into multiple parts and in multiple source files. All parts are combined into one single class during compile time. All parts should contain the keyword partial,should be of the same accessibility. All parts should be present in the same assembly for it to be included during compile time.

Syntax

  • public partial class MyPartialClass { }

Remarks

  • Partial classes must be defined within the same assembly, and namespace, as the class that they are extending.

  • All parts of the class must use the partial keyword.

  • All parts of the class must have the same accessibility; public/protected/private etc..

  • If any part uses the abstract keyword, then the combined type is considered abstract.

  • If any part uses the sealed keyword, then the combined type is considered sealed.

  • If any part uses the a base type, then the combined type inherits from that type.

  • The combined type inherits all the interfaces defined on all the partial classes.



Got any C# Language Question?