• C#委托使用


    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 WindowsFormsApp1
    {
        public delegate void DelegateParam(List<string> _string);
    
        public partial class Form2 : Form
        {
            public event DelegateParam Transmit;
            public Action<string> action;
            public Func<string,int> func;
            public Predicate<string> predicate;
            public Form2()
            {
                InitializeComponent();
                this.button2.Click += Button2_Click;         
            }
            private void Button2_Click(object sender, EventArgs e)
            {
                Transmit?.Invoke(new List<string>() { this.label1.Text.ToString() });
                action?.Invoke(this.label1.Text.ToString());
                int? a = func?.Invoke(this.label1.Text.ToString());
                MessageBox.Show(a.ToString());
                bool? status= predicate?.Invoke(this.label1.Text.ToString());
                MessageBox.Show(status.ToString());
            }
        }
    }
    
    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 WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 form2 = new Form2();
                form2.Transmit += new DelegateParam(DelegateReceiveParam);
                form2.action += new Action<string>(ActionReceiveParam);
                form2.func += new Func<string, int>(FuncReceiveParam);
                form2.predicate += new Predicate<string>(PredicateReceiveParam);
                form2.Show();
            }
            public void DelegateReceiveParam(List<string> vs)
            {
                this.label1.Text = vs[0];
            }
            public void ActionReceiveParam(string vs)
            {
                this.label1.Text = vs;
            }
            public int FuncReceiveParam(string vs)
            {
                this.label1.Text = vs;
                return 1;
            }
            public bool PredicateReceiveParam(string vs)
            {
                this.label1.Text = vs;
                return true;
            }
        }
    }
    
  • 相关阅读:
    javascript 显示类型转换
    javascript 隐式类型转换
    inline/inline-block/block 的区别
    javascript 类型检测
    title与h1的区别、b与strong的区别、i与em的区别?
    CSS定位方式有哪些?position属性的值有哪些?他们之间的区别是什么?
    列出display的值,说明他们的作用。position的值, relative和 absolute定位原点是?
    语义化的理解
    src与href的区别
    img的alt和title的异同?
  • 原文地址:https://www.cnblogs.com/772933011qq/p/10717534.html
Copyright © 2020-2023  润新知