zoukankan      html  css  js  c++  java
  • Action<T> 泛型委托

    1.Action<T> 泛型委托

    这个委托很好用, 不用独立的定义声明一个委托了.  

    下面的委托代码程序还是在.net 1.x时学会的呢, 当时觉得别扭些, 但最后习惯也就习惯了, 最后还保存成模板拷贝来拷贝去的.

            public delegate void DelegateMessage(string username, decimal score); 
            static void Main(string[] args)
            {
                DelegateMessage messageTarget = ShowWindowsMessage;
                messageTarget("lzd", 100);

                Console.ReadKey();
            }

            private static void ShowWindowsMessage(string username, decimal score)
            {
                Console.WriteLine(username + score);
            }

    重构原有的代码, 如下:

    例如:

            static void Main(string[] args)
            {
                Action<string, decimal> messageTarget = ShowWindowsMessage;
                messageTarget("lzd", 100);

                Console.ReadKey();
            }

            private static void ShowWindowsMessage(string username, decimal score)
            {
                Console.WriteLine(username + score);
            }

  • 相关阅读:
    Linux 让终端走代理的几种方法
    golang 项目框架开发
    tensorflow + python + keras 版本对应关系
    Mac OS X下的ldd工具——otool
    jumpserver的安装
    golang 设置代理
    mac install Docker version 19.03.8
    SpringBoot + Spring Cloud Eureka 服务注册与发现
    SpringBoot + Spring Cloud Consul 服务注册和发现
    前端实现大文件上传
  • 原文地址:https://www.cnblogs.com/liuzhendong/p/2266569.html
Copyright © 2011-2022 走看看