委托调用方法的4种方式。

using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
    delegate void DelFunc(string a);
    //delegate void FUNC<int ,int,string>( );
    class Program
    {
        
        public static void Fun1(string str)
        {
            List<int> list = new List<int>();
            Dictionary<int, object> dic = new Dictionary<int, object>();
            Console.WriteLine(str+"new");
        }
        public static void Fun2(string str)
        {
            Console.WriteLine(str + "非new");
         
        }
        static void Main(string[] args)
        {
            DelFunc del = new DelFunc(Fun1);
            del += Fun2;
            del += delegate(string str)
            {
                Console.WriteLine(str+"匿名方法");
            };
            del+=str=>Console.WriteLine(str+"lamada表达式");
            del("赋值给委托变量,通过");

            Console.ReadKey();
        }
    }
}
new,+=,delegate匿名方法,lamada表达式(就是方法,匿名的)

相关文章:

  • 2021-11-18
  • 2022-12-23
  • 2021-09-13
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-16
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-04-15
相关资源
相似解决方案