Home » C# Partial Method

C# Partial Method

Partial method is a special type of method which is declared and defined in two separate partial classes. Declaration part represents signature and presents in a partial class. The definition part provides implementation of the method and resides in separate partial class.

The concept of partial method is helpful when we have declaration and definition of method in two separate files. If definition (implementation) of method is not provided, compiler removes the signature at compile time.

There are some rules and restrictions apply to the partial method.

  • The signature of partial method must be same in both partial classes.
  • The partial method must return void.
  • No access modifiers are allowed.
  • Partial methods are implicitly private.

Let’s see an example that implements the partial method. This example includes two partial classes. One contains declaration part and second contains definition of the method.

C# Partial Method Example

Output

Welcome to the TutorAspire 

You may also like