KC *_*C P -1 c# asynchronous async-await
我们如何在没有 out 参数的 C# 中安全地使用 async-await。
例如
async public void someMethod(){
     await someOtherMethod (out string outputFromSomeOtherMethod);
     .......
     .....
} 
简而言之,您不(并且您不能),我们使用 return
此外,当你考虑它时,它没有任何意义,它是一个在它喜欢的时候完成的任务,如果你能做到,你会强迫它等待 out 参数
public async Task<SomeResult> someOtherMethod() { .. }
...
var myAwesomeResult = await someOtherMethod();
此外,您冷使用 a delegate,func<T,U>或Action<T>作为参数
public async Task someOtherMethod(Action<bool> someResult)
{
   await somestuff;
   someResult(true);
}
...
await someOtherMethod(b => YayDoSomethingElse(b));
Ooor 正如Daniel A. White评论的那样,ValueTuple如果您需要轻松访问多种返回类型,则可以返回 a
public async Task<(int someValue,string someOtherValue)> someOtherMethod() {.. }
| 归档时间: | 
 | 
| 查看次数: | 1583 次 | 
| 最近记录: |