What is partial methods in c#

Smith
Smith
None
2568 Points
74 Posts

Hi,

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

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

Share:   fb twitter linkedin
Answers
Mayank
Mayank
Member
194 Points
12 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