C# 如何在c中使用带out参数的异步等待#

C# 如何在c中使用带out参数的异步等待#,c#,asynchronous,async-await,C#,Asynchronous,Async Await,在没有out参数的情况下,如何在C#中使用async wait呢 比如说 async public void someMethod(){ await someOtherMethod (out string outputFromSomeOtherMethod); ....... ..... } 简而言之,您没有(也不能),我们使用return 另外,当你考虑它的时候,它没有任何意义,它是一个在它喜欢的时候完成的任务,如果你可以这样做,你会强迫它等待out参数 o

在没有out参数的情况下,如何在C#中使用async wait呢

比如说

async public void someMethod(){
     await someOtherMethod (out string outputFromSomeOtherMethod);
     .......
     .....

} 
简而言之,您没有(也不能),我们使用
return

另外,当你考虑它的时候,它没有任何意义,它是一个在它喜欢的时候完成的任务,如果你可以这样做,你会强迫它等待out参数

oo或者如前所述,如果需要轻松访问多个返回类型,可以返回
ValueTuple

public async Task<(int someValue,string someOtherValue)> someOtherMethod() {.. }
public异步任务someOtherMethod(){..}

您还可以返回一个可能有意义的元组。@DanielA.White感谢更新和属性仅对事件处理程序使用async void。在示例中返回任务,其中与
wait
一起使用的方法,使用
out
参数是足够安全的。因为可以使用此参数的下一行将仅在方法完成后执行。
public async Task someOtherMethod(Action<bool> someResult)
{
   await somestuff;
   someResult(true);
}

...

await someOtherMethod(b => YayDoSomethingElse(b));
public async Task<(int someValue,string someOtherValue)> someOtherMethod() {.. }