Partial Classes in .NET 2.0

If you are familiar with ASP.NET 1.1 , you must know that if you are composing one aspx page right from your designer and you go to the code-behind of your aspx page you will find all the controls of the page are declared as protected variables in your class that inherits from System.Web.UI.Page , now in ASP.NET 2.0 Microsoft introduced a new term which is "Partical Classes" if you design one page in the webforms desigener and you switch to code view you will not find any conrols declared you will just find a definition for one class for example :

public partial class EditEmployees_aspx
{

}

And you will find at the top of the code-behind all the required namespaces required for that page , this keeps your code-behind compact and clean as it will only contains the event handlers and only custom code written by the progammer.

Have you ever wanted to add one method to a class shared between you and other team members but you cannot because one member is checking out the class file and the multiple checkouts is turned off by VSS administrator , I guess you faced it before.And in some situations you may need to divide your class into separate files as the file is getting bulky and you need to divide it.

Partial classes provide a solution for that problem as you can split one class on more than on source file and at compilation time all the files are merged to compile and get the full class output.

To split your class/struct/interface to more than one file you should use the keyword modifier partial

Links to this post:

Create a Link