zoukankan      html  css  js  c++  java
  • [C#] 委托与匿名方法

    using System;
     
    namespace 匿名函数
    {
        class Program
        {
            delegate void TestDelegate(string s);
     
            static void M(string s)
            {
                Console.WriteLine("A参数为:{0}", s);
            }
     
            static void Main(string[] args)
            {
                //1. 委托的基本写法,及调用
                TestDelegate testDeleA = new TestDelegate(M);//通过委托的实例化将之与方法绑定
                testDeleA("hahahah");
     
                //2. 使用匿名表达式构造委托调用方法
                //C#2.0 Anonymous Method,其结构为:delegate+(各个参数)+{函数体}
                TestDelegate testDeleB = delegate (string s) { Console.WriteLine("B参数为:{0}", s); };//直接通过delegate声明将之与函数体绑定
                testDeleB("hehehehe");
                //C#3.0, 引入lamda表达法,Lambda Expression
                TestDelegate testDeleC = (x) => { Console.WriteLine("C参数为:{0}", x); };
                testDeleC("hohoho");
     
                Console.ReadKey();
            }
     
        }
    }
     
     
  • 相关阅读:
    CentOS 7.4 如何安装 MariaDB 10.3.9 Stable 数据库
    xxx is not in the sudoers file. This incident will be reported.
    CentOS 7.4 上如何安装 tomcat 9
    CentOS 7.4 下面安装 jdk 10 的一点总结
    CentOS 7.4 下安装 Nginx
    MySQL数据库常用操作
    chart学习
    Ext需要的文件目录
    获取浏览器信息
    运行容器
  • 原文地址:https://www.cnblogs.com/xihong2014/p/13898746.html
Copyright © 2011-2022 走看看