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 ?
Asked
Active
Viewed 1,190 times
8
-
this could help : http://msdn.microsoft.com/en-us/library/hh156513.aspx – A.K. Feb 05 '14 at 07:27
1 Answers
8
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);
}

har07
- 88,338
- 12
- 84
- 137
-
5BTW, `Tuple.Create()` is often shorter than `new Tuple()`, because you can use type inference with it. – svick Feb 05 '14 at 11:00