zoukankan      html  css  js  c++  java
  • lanmada表达式神马叫优雅

    看看,委托,原来的用法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApp
    {
        delegate string DeleTest(string name); 
        class Program
        {
            static void Main(string[] args)
            {
                DeleTest t = new DeleTest(SomeMethod);
                Console.WriteLine( t("tom"));
            }

            static string SomeMethod(string str)
            {
                return "Hello " +str +" How r u ?";
            }
        }
    }

     其实,委托那句可以这样写

    DeleTest t = SomeMethod;

    下面,变形,库库库库卡,匿名方法出现了

     class Program
        {
            static void Main(string[] args)
            {
                DeleTest t = delegate(string str)
                {
                    return "Hello " +str +" How r u ?";
                };
                Console.WriteLine( t("tom"));
            }
        }

    变形,库库库库卡,lanmada表达市! 

     class Program
        {
            static void Main(string[] args)
            {
                DeleTest t = str=>
                {
                    return "Hello " +str +" How r u ?";
                };
                Console.WriteLine( t("tom"));
            }
        }

     没有最好 只有更好

        class Program
        {
            static void Main(string[] args)
            {
                DeleTest t = str=>"Hello " +str +" How r u ?";   
                Console.WriteLine( t("tom"));
            }
        }

    什么叫优雅,介旧叫优雅

  • 相关阅读:
    Dynamics CRM for Outlook问题集
    Dynamics CRM
    VMWare安装CentOS-6.3-x86_64-minimal和LAMP
    Microsoft Dynamics CRM Update Rollup
    Reporting Service 迁移: 从2005到2008
    [转]非常好的vsftpd安装于配置
    关闭水滴直播平台 周鸿祎曾态度强硬
    贾跃亭此前曾公开表示,“法拉第未来计划于2
    爆出的法拉第未来(Faraday Future,以下简称“FF”)
    YII2笔记之三
  • 原文地址:https://www.cnblogs.com/imxh/p/2230953.html
Copyright © 2011-2022 走看看