What is partial methods in c#

374 Points
112 Posts


What is partial methods in c#? How and when to use it.

Views: 8140
Total Answered: 1
Total Marked As Answer: 1
Posted On: 12-Apr-2016 19:06

Share:   fb twitter linkedin
78 Points
24 Posts

Hey smith,

Partial methods are introduce in .Net framework 3.0. So you can split the definition of a class 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.

Example for partial method 

// Definition in file1.cs 
partial void onNameChanged();
// Implementation in file2.cs 
partial void onNameChanged()
// method body

 There are some conditions for partial methods:

  • Signatures in both parts of the partial type must match.
  • The method must return void.
  • No access modifiers are allowed. Partial methods are implicitly private.
Posted On: 16-Apr-2016 01:09
 Log In to Chat