Day 24-Partial classes

Partial classes allow us to split a class into  2 or more files.All these part are then combined into single class,when the application is compiled.The partial keyword can also be used to split a struct or an interface over two or more files

  • Example-Visual studio uses partial classes to  separate automatically generated system code from the developers code.When you add a webform,two .cs file is generated
  1. Webform.aspx.cs-Contain the developer code
  2. Webform.aspx.designer.cs-Contain the system generated code


  •     All the partial class definitions must be in the same assembly and          namespace.
  •     All the parts must have the same accessibility like public or private,        etc.
  •     If any part is declared abstract then the whole class is declared of         the same type.
  •     If any part is declared  sealed  then the whole class is declared of        the same type.
  •     Different parts can have different base types and so the final class will   inherit all the base types
  •     The Partial modifier can only appear immediately before the                keywords class, struct, or interface.
  •     Nested partial types are allowed.