All i want to use Out keyword with my Async function. According to MSDN it is not possible Async modifiers not supports to the out keyword. So is there any alternate in .Net framework 4.5/4.0 ?
What is the replacement of Out keyword for Async methods in .Net 4.5 and 4.0?
Asked Answered
this could help : msdn.microsoft.com/en-us/library/hh156513.aspx –
Winded
You can declare the async function to return Tuple
instead. With that the function still able to return multiple values without using out
parameter.
public async Task<Tuple<string, int, bool>>SomeFunctionAsync()
{
return new Tuple<string, int, bool>("foo", 0, false);
}
For Reference :
UPDATE :
you can use shorter syntax as suggested by @svick in comment. Following function return the same value, but using Tuple.Create
:
public async Task<Tuple<string, int, bool>>SomeFunctionAsync()
{
return Tuple.Create("foo", 0, false);
}
BTW,
Tuple.Create()
is often shorter than new Tuple()
, because you can use type inference with it. –
Saideman © 2022 - 2024 — McMap. All rights reserved.