Share via


partial (Method) (C# Reference)

A partial method has its signature defined in one part of a partial type, and its implementation defined in another part of the type. Partial methods enable class designers to provide method hooks, similar to event handlers, that developers may decide to implement or not. If the developer does not supply an implementation, the compiler removes the signature at compile time. The following conditions apply to partial methods:

  • Signatures in both parts of the partial type must match.

  • The method must return void.

  • No access modifiers or attributes are allowed. Partial methods are implicitly private.

The following example shows a partial method defined in two parts of a partial class:

namespace PM
{
    partial class A
    {
        partial void OnSomethingHappened(string s);
    }

    // This part can be in a separate file.
    partial class A
    {
        // Comment out this method and the program
        // will still compile.
        partial void OnSomethingHappened(String s)
        {
            Console.WriteLine("Something happened: {0}", s);
        }
    }
}

For more information, see Partial Classes and Methods (C# Programming Guide).

See Also

Reference

partial (Type) (C# Reference)

Other Resources

C# Reference