zoukankan      html  css  js  c++  java
  • 委托-匿名方法

    一,无参数无返回

    namespace 委托
    {
        class Program
        {
            public delegate void Method();
            static void Main(string[] args)
            {
                Method method = delegate ()
                  {
                      Console.WriteLine("----无参数返回----");
                  };
                //使用方法
                method();
                Console.Read();
            }
    
        }
    }
    

    二,无参数有返回

    namespace 委托
    {
        class Program
        {
            public delegate void Method(int a);
            static void Main(string[] args)
            {
                Method method = delegate (int a)
                  {
                      Console.WriteLine($"{a}");
                  };
                //使用方法
                method(10);
                Console.Read();
            }
    
        }
    }
    

    三,有参数有返回

    namespace 委托
    {
        class Program
        {
            public delegate int  Method(int a);
            static void Main(string[] args)
            {
                Method method = delegate (int a)
                  {
                      return a;
                  };
                //使用方法
                int result= method(10);
                Console.WriteLine(result);
                Console.Read();
            }
    
        }
    }
    

      

      

  • 相关阅读:
    hdu 1978
    hdu 2700
    hdu 1176
    hdu 2390
    hdu 2707
    hdu 1804
    hdu 2703
    hdu 2572
    hdu 1171
    React有状态组件和无状态组件
  • 原文地址:https://www.cnblogs.com/Luck1996/p/11983625.html
Copyright © 2011-2022 走看看