zoukankan      html  css  js  c++  java
  • Some examples about how to write anonymous method and lambda expression

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace LandmaExpressionDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                //anonymous method
                Action ac = delegate() { Console.WriteLine("hello delegate"); };
                ac();
    
                //Use Action<T> to create anonymous method with parameters
                Action<string> ac2 = delegate(string strMessage) { Console.WriteLine(strMessage); };
                ac2("hello world2");
    
                //Pass the anonymous method to another method as parameter
                ActionHelper(delegate(string strMessage) { Console.WriteLine(strMessage); });
    
                //use landmar expression as parameter to another method
                ActionHelper(fw => Console.WriteLine(fw));
    
                //Use lambda expression as a delegate
                Action ac3 = () => Console.WriteLine("hello ac3");
                ac3();
    
    
            }
    
            public delegate void DisplayMessageDelegate(string strMesssage);
    
            public static void ActionHelper(Action<string> ac)
            {
                ac("hello world3");
            }
    
            //Useful references
            //1. http://msdn.microsoft.com/en-us/library/018hxwa8.aspx
            //2. http://msdn.microsoft.com/en-us/library/bb549151.aspx
            //3. http://msdn.microsoft.com/en-us/library/bb397687.aspx
            //4. http://msdn.microsoft.com/en-us/library/bb534960.aspx
        }
    }
    
  • 相关阅读:
    2019-8-31-win10-uwp-使用-WinDbg-调试
    PHP simplexml_import_dom() 函数
    PHP asXML() 函数
    PHP registerXPathNamespace() 函数
    PHP getNamespaces() 函数
    PHP getName() 函数
    查看收集统计信息的时间间隔
    SPOJ DISQUERY LCA + 倍增
    洛谷P3958 奶酪 并查集
    洛谷P2678 跳石头
  • 原文地址:https://www.cnblogs.com/xiaxi/p/2230229.html
Copyright © 2011-2022 走看看