1. <tfoot id='IzJop'></tfoot>
      <i id='IzJop'><tr id='IzJop'><dt id='IzJop'><q id='IzJop'><span id='IzJop'><b id='IzJop'><form id='IzJop'><ins id='IzJop'></ins><ul id='IzJop'></ul><sub id='IzJop'></sub></form><legend id='IzJop'></legend><bdo id='IzJop'><pre id='IzJop'><center id='IzJop'></center></pre></bdo></b><th id='IzJop'></th></span></q></dt></tr></i><div id='IzJop'><tfoot id='IzJop'></tfoot><dl id='IzJop'><fieldset id='IzJop'></fieldset></dl></div>

      <small id='IzJop'></small><noframes id='IzJop'>

          <bdo id='IzJop'></bdo><ul id='IzJop'></ul>
        <legend id='IzJop'><style id='IzJop'><dir id='IzJop'><q id='IzJop'></q></dir></style></legend>

        Func&lt;string,string&gt; 有什么区别?和委托?

        What is the difference between Funclt;string,stringgt; and delegate?(Funclt;string,stringgt; 有什么区别?和委托?)
        1. <tfoot id='knGX8'></tfoot>
              <tbody id='knGX8'></tbody>
              <bdo id='knGX8'></bdo><ul id='knGX8'></ul>

                <legend id='knGX8'><style id='knGX8'><dir id='knGX8'><q id='knGX8'></q></dir></style></legend>

                <small id='knGX8'></small><noframes id='knGX8'>

              • <i id='knGX8'><tr id='knGX8'><dt id='knGX8'><q id='knGX8'><span id='knGX8'><b id='knGX8'><form id='knGX8'><ins id='knGX8'></ins><ul id='knGX8'></ul><sub id='knGX8'></sub></form><legend id='knGX8'></legend><bdo id='knGX8'><pre id='knGX8'><center id='knGX8'></center></pre></bdo></b><th id='knGX8'></th></span></q></dt></tr></i><div id='knGX8'><tfoot id='knGX8'></tfoot><dl id='knGX8'><fieldset id='knGX8'></fieldset></dl></div>
                  本文介绍了Func&lt;string,string&gt; 有什么区别?和委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我看到代表有两种形式:

                  I see delegates in two forms:

                  A. Func<string, string> convertMethod = lambda 
                  
                  B. public delegate string convertMethod(string value);
                  

                  我不确定这两者之间的实际区别是什么.他们都是代表吗?我相信第一个会使用 lambda,而第二个必须有一种方法来实际执行工作.我可能也很困惑.

                  I'm uncertain of what actually the difference between these two are. Are they both delegates? I believe the first one would use a lambda and the second would have to have a method to actually perform the work. I may be confused too.

                  推荐答案

                  首先,您的两个示例正在做两件完全不同的事情.第一个是声明一个通用委托变量并为其分配一个值,第二个是定义一个 delegate 类型.更完整的例子是:

                  First of all, your two examples are doing two totally separate things. The first is declaring a generic delegate variable and assigning a value to it, the second is just defining a delegate type. Your example, more completely, would be:

                  public static class Program
                  {
                      // you can define your own delegate for a nice meaningful name, but the
                      // generic delegates (Func, Action, Predicate) are all defined already
                      public delegate string ConvertedMethod(string value);
                  
                      public static void Main()
                      {
                          // both work fine for taking methods, lambdas, etc.
                          Func<string, string> convertedMethod = s => s + ", Hello!";
                          ConvertedMethod convertedMethod2 = s => s + ", Hello!";
                      }
                  }
                  

                  但更重要的是,无论是方法,Funcdelegate string convertMethod(string) 都能够保存相同的方法定义、匿名方法或 lambda 表达式.

                  But more to the point, both Func<string,string> and delegate string convertMethod(string) would be capable of holding the same method definitions whether they be methods, anonymous methods, or lambda expressions.

                  至于应该使用哪个,视情况而定.如果您希望您的委托更多地由它接受和返回的内容来定义,那么通用委托是完美的.如果您希望委托有一些特殊的名称,可以更详细地定义委托应该做什么(除了简单的 ActionPredicate 等),那么始终创建自己的委托一个选项.

                  As for which you should use, depends on the situation. If you want your delegate to be defined more by what it takes and returns, then the generic delegates are perfect. If you want the delegate to have some special name that gives more definition of what that delegate should do (beyond simple Action, Predicate, etc) then creating your own delegate is always an option.

                  这篇关于Func&lt;string,string&gt; 有什么区别?和委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                    <tfoot id='zAE8C'></tfoot>
                      <tbody id='zAE8C'></tbody>
                    • <i id='zAE8C'><tr id='zAE8C'><dt id='zAE8C'><q id='zAE8C'><span id='zAE8C'><b id='zAE8C'><form id='zAE8C'><ins id='zAE8C'></ins><ul id='zAE8C'></ul><sub id='zAE8C'></sub></form><legend id='zAE8C'></legend><bdo id='zAE8C'><pre id='zAE8C'><center id='zAE8C'></center></pre></bdo></b><th id='zAE8C'></th></span></q></dt></tr></i><div id='zAE8C'><tfoot id='zAE8C'></tfoot><dl id='zAE8C'><fieldset id='zAE8C'></fieldset></dl></div>

                        <bdo id='zAE8C'></bdo><ul id='zAE8C'></ul>

                          <legend id='zAE8C'><style id='zAE8C'><dir id='zAE8C'><q id='zAE8C'></q></dir></style></legend>

                          <small id='zAE8C'></small><noframes id='zAE8C'>