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

    什么叫优雅,介旧叫优雅

  • 相关阅读:
    sql like模糊查询
    mysql没有delete操作,那是delete from操作,
    j详细说明ava于clone办法
    基于ZooKeeper的Dubbo简单抽样登记中心
    度小于所述过程:es.exe
    Android 支付宝钱包手势password裂纹战斗
    How draw a stem -and -leaf & box-plot display by R.or Python
    POJ 2420 A Star not a Tree? (模拟退火)
    记userscripts.org
    基于最简单的FFmpeg包封过程:视频和音频分配器启动(demuxer-simple)
  • 原文地址:https://www.cnblogs.com/imxh/p/2230953.html
Copyright © 2011-2022 走看看