C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# Partial MethodPartial 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.
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 Exampleusing System; namespace CSharpFeatures { partial class A { // Declaring partial method partial void ShowMSG(string msg); } partial class A { // Implimenting partial method partial void ShowMSG(String msg) { Console.WriteLine(msg); } public static void Main(string[] args) { // Calling partial method. new A().ShowMSG("Welcome to the JavaTpoint"); } } } Output Welcome to the JavaTpoint
Next TopicC# Implicitly Typed Local Variable
|