Action<T> 委托

class Program
    {
        static void Main(string[] args)
        {
            MyDelegate<string>(MyFunc, "Hello World!");
            MyDelegate<int>(MyFunc2, 1000);
            MyDelegate<string>(p => { Console.WriteLine("{0}", p); }, "Hello World");//使用Lambda表达式定义委托
            Console.ReadKey();
        }

        public static void MyDelegate<T>(Action<T> action, T p)
        {
            action(p);
        }
        private static void MyFunc(string s)
        {
            Console.WriteLine(s);
        }
        private static void MyFunc2(int s)
        {
            Console.WriteLine(s);
        }
    }

 
                    
            
                

相关文章:

  • 2021-03-30
  • 2021-11-29
  • 2021-09-20
  • 2022-12-23
  • 2021-11-18
  • 2021-10-28
猜你喜欢
  • 2021-11-29
  • 2021-07-26
  • 2021-11-23
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案