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();
            }
     
        }
    }
     
     
  • 相关阅读:
    什么是级联
    @GeneratedValue
    Spring Data JPA中CrudRepository与JpaRepository的不同
    Spring Data JPA的方法命名规则
    C/S架构的渗透测试-请求加解密及测试
    各类Fuzz字典
    Nessus8.11破解
    xss实验1-20writeup
    IIS短文件名漏洞
    Linux挂载exfat文件系统的U盘
  • 原文地址:https://www.cnblogs.com/xihong2014/p/13898746.html
Copyright © 2011-2022 走看看