C#-partial类型

通过分部类型可以定义要拆分到多个文件中的类、结构或接口。

//file1.cs中
namespace PC
{
    partial class A
    {
        int num = 0;
        void MethodA() { }
        partial void MethodC();
    }
}
//file2.cs中
namespace PC
{
    partial class A
    {
        void MethodB() { }
        partial void MethodC() { }
    }
}

代码实例

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("正在打开窗体");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_42274148/article/details/89709412