Topic description
The Program class is divided into two parts by the partial modifier. A partial method is defined in the first part and referenced in the other part. (console application)
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace partial method { public partial class Program { //declare and define a partial class //Declare the partial method, the default is private, or you can add private manually partial void Write();//声明 partial void Write()//定义 { Console.WriteLine("This is a partial method"); } } public partial class Program { static void Main(string[] args) { Program p = new Program(); p.Write(); } } }
***Partial method: the method declaration contains the partial modifier
Partial methods must be declared in the distribution class or part structure and must be private
Partial methods have severe limitations
1> The method must return void, only private by default
2> Partial methods cannot be virtual and extern
3> Partial methods can have ref parameters, but not out parameters