How you create partial methods?

 Posted by Tripati_tutu on 11/16/2010 | Category: C# Interview questions | Views: 2460 | Points: 40

To create a partial method we have to declare two parts that is definition or we can say declaration and the implementation. Here the implementation is optional i.e. when it is not declared then all calls to the method are removed at compile time. So that the code in partial class can freely use partial method even if implementation is not provided. If implementation is not declared then the compiler will define the declaration and will call to the methods.

Following points to keep when creating partial methods…

• The declaration of Partial method must begin with a partial keyword.
• The return type of a partial method must be void.
• Partial methods can have ref parameters but not the out parameters.
• The default type of Partial method is private, and it cannot be virtual.
• Partial methods cannot be extern, because it determines whether they are defining or implementing.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response