zoukankan      html  css  js  c++  java
  • 委托

    1

        class Program
        {
            private delegate string GetAStr();
    
            static void Main(string[] args)
            {
                //int x = 40;
                //string s = x.ToString();
    
                //Console.WriteLine(s);
    
                //GetAStr getAStr = new GetAStr(x.ToString);
    
                //Console.WriteLine(getAStr.Invoke());
    
                PrintStr method = Method1;
                Printf(method);
                method = Method2;
                Printf(method);
                Console.ReadKey();
    
    
            }
    
            private delegate void PrintStr();
            static void Printf(PrintStr print)
            {
                print();
            }
    
            static void Method1()
            {
                Console.WriteLine("method1");
            }
            static void Method2()
            {
                Console.WriteLine("method2");
            }
        }

    2 action

        class Program
        {
            static void PrintStr(int i)
            {
                Console.WriteLine(i);
            }
    
            static void PrintStr(string s)
            {
                Console.WriteLine(s);
            }
            static void PrintStr(string s, int i)
            {
                Console.WriteLine(s);
            }
    
    
            static void Main(string[] args)
            {
                //int x = 100;
                //Action a = PrintStr;
                //Action<int> a = PrintStr;
                Action<string, int> a = PrintStr;
     
            }
        }

    3 func

        class Program
        {
            static int Test1()
            {
                return 1;
            }
            static int Test2(string s)
            {
                //Console.WriteLine(s);
                return 100;
            }
    
            static void Main(string[] args)
            {
                Func<string,int> a = Test2;
                Console.WriteLine(a("sad"));
                Console.ReadKey();
            }
        }
  • 相关阅读:
    G D 3 2 预 处 理 符 号 配 置 中 定 义
    指针接收函数
    SMT(SF)
    电流高端采样问题
    简单分析一个采集交流电压平均值的电路
    i--和--i的区别
    结构体共用体的使用
    .net Filter 和 代理模式杂谈
    Spring boot 日志 Logback
    spring boot 使用 mongodb
  • 原文地址:https://www.cnblogs.com/wxhao/p/13624864.html
Copyright © 2011-2022 走看看