简体   繁体   中英

What is the replacement of Out keyword for Async methods in .Net 4.5 and 4.0?

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 ?

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM