How can we use async-await in C# with out parameter safely.
for example
async public void someMethod(){
await someOtherMethod (out string outputFromSomeOtherMethod);
.......
.....
}
How can we use async-await in C# with out parameter safely.
for example
async public void someMethod(){
await someOtherMethod (out string outputFromSomeOtherMethod);
.......
.....
}
In short, you don't (and you can't), we use a return
Also, when you think about it, it doesn't make any sense, its a task that finishes when it likes, if you could do that you would be forcing it to wait for the out parameter
public async Task<SomeResult> someOtherMethod() { .. }
...
var myAwesomeResult = await someOtherMethod();
Also, you cold use a delegate
, func<T,U>
or Action<T>
as a parameter
public async Task someOtherMethod(Action<bool> someResult)
{
await somestuff;
someResult(true);
}
...
await someOtherMethod(b => YayDoSomethingElse(b));
Ooor as Daniel A. White commented, you could return a ValueTuple
if you need easy access to multiple return types
public async Task<(int someValue,string someOtherValue)> someOtherMethod() {.. }