简体   繁体   English

.Net 4.5和4.0中Async方法的Out关键字的替换是什么?

[英]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. 所有我想在我的异步功能中使用Out关键字。 According to MSDN it is not possible Async modifiers not supports to the out keyword. 根据MSDN,Async修饰符不支持out关键字。 So is there any alternate in .Net framework 4.5/4.0 ? 那么.Net framework 4.5 / 4.0中还有其他替代品吗?

You can declare the async function to return Tuple instead. 您可以声明异步函数来返回Tuple With that the function still able to return multiple values without using out parameter. 有了这个功能,该函数仍然能够返回多个值而不使用out参数。

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. 您可以在评论中使用@svick建议的较短语法。 Following function return the same value, but using Tuple.Create : 以下函数返回相同的值,但使用Tuple.Create

public async Task<Tuple<string, int, bool>>SomeFunctionAsync()
{
    return Tuple.Create("foo", 0, false);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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