[RESOLVED]When to Use Partial Class ?.Give Appropriate Situation ?.

 H i Friends ,

               When to use Partial Class ?.. IF do so what is the Advantages with Example .

Thanks in Advance ,

Karthik. K



Whenever you want to scatter your class definition to multiple files, then, partial is the way to go.

For example, you add the webreference and have the proxy with you. You want to extend some class for your business logic need, you can extend it if it is a partial class.

See from MSDN reference:

It is possible to split the definition of a
or a struct, an
interface or a method over two or more source files. Each source file contains a section of the type or method definition, and all parts are combined when the application is compiled.

There are several situations when splitting a class definition is desirable:

  • When working on large projects, spreading a class over separate files enables multiple programmers to work on it at the same time.

  • When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when it creates Windows Forms, Web service wrapper code, and so on. You can create code that uses
    these classes without having to modify the file created by Visual Studio.


You might also feel this SO discussion worthy:


Another good article explaining similar points:


Leave a Reply