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

      1. <small id='DoerA'></small><noframes id='DoerA'>

      2. C#:使用布尔返回类型创建多播委托

        C#:Creating Multicast delegate with boolean return type(C#:使用布尔返回类型创建多播委托)

        <tfoot id='Pve2X'></tfoot>

      3. <legend id='Pve2X'><style id='Pve2X'><dir id='Pve2X'><q id='Pve2X'></q></dir></style></legend>

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

          • <bdo id='Pve2X'></bdo><ul id='Pve2X'></ul>
                <tbody id='Pve2X'></tbody>
              • <small id='Pve2X'></small><noframes id='Pve2X'>

                  本文介绍了C#:使用布尔返回类型创建多播委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  海技术,

                  在 C# 中,我们如何定义接受 DateTime 对象并返回布尔值的多播委托.

                  in C#, how can we define the multicast delegate which accepts a DateTime object and return a boolean.

                  谢谢

                  推荐答案

                  public delegate bool Foo(DateTime timestamp);
                  

                  这是使用您描述的签名声明委托的方法.所有代表都可能是多播的,它们只需要初始化.如:

                  This is how to declare a delegate with the signature you describe. All delegates are potentially multicast, they simply require initialization. Such as:

                  public bool IsGreaterThanNow(DateTime timestamp)
                  {
                      return DateTime.Now < timestamp;
                  }
                  
                  public bool IsLessThanNow(DateTime timestamp)
                  {
                      return DateTime.Now > timestamp;
                  }
                  
                  Foo f1 = IsGreaterThanNow;
                  Foo f2 = IsLessThanNow;
                  Foo fAll = f1 + f2;
                  

                  调用 fAll,在这种情况下会同时调用 IsGreaterThanNow()IsLessThanNow().

                  Calling fAll, in this case would call both IsGreaterThanNow() and IsLessThanNow().

                  这不能让您访问每个返回值.你得到的只是返回的最后一个值.如果要检索每个值,则必须像这样手动处理多播:

                  What this doesn't do is give you access to each return value. All you get is the last value returned. If you want to retrieve each and every value, you'll have to handle the multicasting manually like so:

                  List<bool> returnValues = new List<bool>();
                  foreach(Foo f in fAll.GetInvocationList())
                  {
                      returnValues.Add(f(timestamp));
                  }
                  

                  这篇关于C#:使用布尔返回类型创建多播委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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() 和泛型:错误绑定到目标方法)
                  <i id='3zlSv'><tr id='3zlSv'><dt id='3zlSv'><q id='3zlSv'><span id='3zlSv'><b id='3zlSv'><form id='3zlSv'><ins id='3zlSv'></ins><ul id='3zlSv'></ul><sub id='3zlSv'></sub></form><legend id='3zlSv'></legend><bdo id='3zlSv'><pre id='3zlSv'><center id='3zlSv'></center></pre></bdo></b><th id='3zlSv'></th></span></q></dt></tr></i><div id='3zlSv'><tfoot id='3zlSv'></tfoot><dl id='3zlSv'><fieldset id='3zlSv'></fieldset></dl></div>
                  • <small id='3zlSv'></small><noframes id='3zlSv'>

                      1. <tfoot id='3zlSv'></tfoot><legend id='3zlSv'><style id='3zlSv'><dir id='3zlSv'><q id='3zlSv'></q></dir></style></legend>
                          <bdo id='3zlSv'></bdo><ul id='3zlSv'></ul>
                              <tbody id='3zlSv'></tbody>