What is partial methods in c#

Smith
Smith
Participant
360 Points
110 Posts

Hi,

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

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

Share:   fb twitter linkedin
Answers
Mayank
Mayank
Member
78 Points
24 Posts
Marked as answer      

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
banner

Blog

Active User (2)

 Log In to Chat