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();
            }
        }
  • 相关阅读:
    C# SendKeys用法
    Winform的高DPI问题
    CefSharp在高DPI的屏幕上出现黑边(winform)
    CefSharp支持flash
    CeSharp支持MP4
    C#加密解密总览
    Eclipse 调试Bug之使用断点的七大技巧
    详解Eclipse断点
    怎样编写高质量的java代码
    Quartz任务调度基本使用
  • 原文地址:https://www.cnblogs.com/wxhao/p/13624864.html
Copyright © 2011-2022 走看看