分部方法

题目描述  

通过partial修饰符把Program类分为两部分,在第一部分定义一个分部方法,在另一部分中引用。(控制台应用程序)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 分部方法
{
    public partial class Program
    {
        //声明与定义一个分部类
        //声明分部方法,默认为私有,也可以人为加上private
        partial void Write();//声明
        partial void Write()//定义
        {
            Console.WriteLine("这是一个分部方法");
        }
    }
    public partial class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            p.Write();
        }
    }
}

***分部方法:方法声明中含有partial修饰符

分部方法必须在分布类或分部结构中声明,必须私有

分部方法有着严格的限制

1>方法必须返回void,只能默认private

2>分部方法不能为virtual和extern 

3>分部方法可以有ref参数,不能有out参数

猜你喜欢

转载自blog.csdn.net/wyj____/article/details/80178375
今日推荐