• Delegate类型和lambda表达式、匿名函数之间的转化


    private void ThreadToMainExeption()
      {
       Thread t = new Thread(() =>
       {
        try
        {
         Console.WriteLine("work thread");
        }
        catch (Exception e)
        {
         this.Invoke((Action)delegate
         {
          throw e;
         });

         //无法将lambda表达式转为delegate类型。
         //this.Invoke(() =>
         //{

         //});

         //无法将匿名方法转为委托类型。
         //this.Invoke(delegate
         //{
         //    throw e;
         //});

         //该段代码可以通过,真矫情。
         //Func<string, string> anonDel = delegate(string param)
         //{
         //    param += "ddd";
         //    return param;
         //};
         //this.Invoke(anonDel);
        }
       });

    Action是委托实例,而匿名方法只是一个方法,不是对象。但是可以通过类型转化转为对象。

    clr会为它声明个匿名类。

  • 相关阅读:
    exp 和imp 与expdp / impdp 区别
    nginx优化
    nginx root alias proxypass
    mysql3
    logrotate 用法
    SQL执行顺序
    http与RPC的关系
    docker
    windows 时间同步
    Java生成指定长度的随机字符串
  • 原文地址:https://www.cnblogs.com/363546828/p/2419140.html
Copyright © 2020-2023  润新知