Stats

72 Contributors: 6 Tuesday, July 11, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap
Download eBook

Partial class and methods

Download c# eBook

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.

Related Examples