22-C#的委托简单使用-2

C#的委托简单使用-2

csharp 复制代码
namespace WindowsFormsApp1
{
    public delegate void mydele(int x);//定义一个委托
    public partial class Form1 : Form
    {
        mydele mydele1;
        public Form1()
        {
            InitializeComponent();
            mydele1 = new mydele(run1);//委托实例化
            mydele1 += run2;
        }

        private void run1(int x)
        {
            textBox1.Text = x.ToString();
        }
        private void run2(int x)
        {
            textBox2.Text = (x/10).ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            mydele1(12021231);
        }
    }
}