Partial class and methods
suggest changeIntroduction
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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents