| Simplest definition of partial classes and its rules?
Partial class is usually used to split definition of class in 2 or more classes which should be either in one source code file or in more than one source file. Here we can create class definition in multiple files but these are compiled as only one class at run time. And when we create a instance of this partial class then we can access all methods from source files with same object. So we used "Partial" keyword with all the class names that we want to bind together with the same name of a class in the same namespace. Below image will clarify you the definition of partial class:-
Rules:-
(1)All definition of partial class must be in same seembly and namespace.
(2)All parts have the same accessibility like public or private, etc.
(3)If we declared and part as abstract, sealed or base type then the whole class is declared of the same type.
(4)partial Nested types are allowed.
(5)Different parts can have different base types and so the final class will inherit all the base types.
(6)Partial modifier can only appear immediately before the keywords class, struct, or interface.
(7)Partial methods can be generic or static methods.
(8)Partial methods can have in or ref but not out parameters.
(9)Partial methods are implicitly private methods, so cannot be virtual.
(10)Partial methods must use the partial keyword and must return void.
(11)Partial methods can have in or ref but not out parameters. | | |