【问题标题】:Use out parameter with System.Servicemodel.ClientBase<>.ChannelBase<> EndInvoke将 out 参数与 System.Servicemodel.ClientBase<>.ChannelBase<> EndInvoke 一起使用
【发布时间】:2019-09-09 10:04:35
【问题描述】:

This is the official page of the method 我想我需要使用“out”参数作为参数。我有这样的方法:

bool GetInfo(out List<foo> bar);

如何在不更改调用方法的情况下使用 out 参数?在这种情况下,我真的不想返回 Set of bool 和 List。

到目前为止,我尝试过这样使用它:

EndInvoke("GetInfo", new object[] { out bar }, ...);
EndInvoke("GetInfo", new object[] { bar }, ...);
EndInvoke("GetInfo", new object[] { }, ...);
EndInvoke("GetInfo", null, ...);
List<foo> bar = (List<foo>)EndInvoke("GetInfo", new object[] { bar }, ...);

但没有什么真正有意义,对象数组中的输出栏显然根本不起作用。

【问题讨论】:

    标签: c# invoke out


    【解决方案1】:

    显然你只是忽略了 out 参数。这是我目前的工作解决方案:

    public bool GetInfo(out List<foo> bar) {
       bar = new List<foo>();
       object[] args = new object[] { bar };
       IAsyncResult result = BeginInvoke("GetInfo", args, null, null);
       EndInvoke("GetInfo", args, result);
       bar = (List<foo>)args[0];
       return true;
    }
    

    Invokes 调用使用问题中给出的接口行中的 GetInfo 方法。它们是使用相同名称的 2 个不同的方法,所以如果有人看到这个并认为它可以帮助他们,请不要被它弄糊涂。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 2019-05-05
      • 1970-01-01
      • 2014-03-23
      • 2017-10-02
      • 1970-01-01
      相关资源
      最近更新 更多