Using partial classes and methods
First, we should say what the partial
keyword is. The partial
keyword tells the compiler that there can be more than one source file containing the type or method definition. The partial
keyword can be used with a class
, a struct
, an interface
, or a method. The definitions are combined during the compilation process of the application.
Partial classes
Splitting the classes into multiple definitions is mostly done when there is some automatically generated code, such as Windows Forms or web service wrapper code, or when multiple programmers need to modify a single class
definition at the same time. Splitting can also help you refactor some legacy code when you find a class
definition comprising thousands of lines of code. Splitting this code into multiple smaller chunks will make it easier to refactor.
The split definition uses the partial
keyword to notify the compiler that there may be another class definition:
// File1.cs public partial...