美文网首页
委托,匿名函数

委托,匿名函数

作者: 山猪打不过家猪 | 来源:发表于2022-07-17 14:36 被阅读0次

委托

  • 类似于python反射,将函数名当参数使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;


namespace delegate_test
{
    class Program
    {
        public delegate void DeleSayHi(string str_name);
        static void Main(string[] args)
        {

            SayEnglish("张三");
            Test("彭菊菊", SayChinese);
            Test("fxx", SayEnglish);
            Console.ReadKey();
        }

        public static void Test(string str_name, DeleSayHi del)
        {
            del(str_name);
        }

        public static void SayChinese(string str_name)
        {
            Console.WriteLine($"我是{str_name}");

        }
        public static void SayEnglish(string str_name)
        {
            Console.WriteLine($"My name is {str_name}");
        }
    }
}

匿名函数

相关文章

网友评论

      本文标题:委托,匿名函数

      本文链接:https://www.haomeiwen.com/subject/suxdirtx.html