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);
            }

  • 相关阅读:
    static 和final
    Integer中getInteger(),valueof()
    Integer和String "+""=="方法的不同
    java中Integer常量池
    用jvm指令分析String 常量池
    多线程、线程安全
    String字符串缓冲区、StringBuffer
    TCP通信---文件上传案例、多线程文件上传
    网络通信协议、UDP通信、TCP通信
    Java线程-- 线程池
  • 原文地址:https://www.cnblogs.com/liuzhendong/p/2266569.html
Copyright © 2011-2022 走看看