A partial class is an ability to separate the implementation of a single class into multiple files and these files are combined to create in a single class when the code is compiled. Partial classes are created by using the keyword partial.
public partial class Class1 { //implementation }
Here are some points to consider while implementing the partial classes:-
- Use the partial keyword in each part of the partial class.
- The name of each part of the partial class should be the same but the .cs file name can be different.
- All parts of a partial class should be in the same namespace.
- Each part of a partial class should be in the same assembly or DLL, in other words, you can’t create a partial class in source files of a different class library project.
- Each part of a partial class has the same accessibility. (like, public/ internal)
- If you inherit a class or interface on a partial class then it is inherited on all parts of a partial class.
- Sealed part of the partial class results in the entire class being sealed.
- If a part of a partial class is abstract then the entire class will be considered an abstract class.