如何返回任务< tuple< list< int&gt ;, bool> ? [英] How to return task<tuple<list<int>, bool> ?

查看:109
本文介绍了如何返回任务< tuple< list< int&gt ;, bool> ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 public async Task<Tuple<List<int>, bool>> GetQuestionOptions(List<studs> studsList)
{
//code
return new Tuple<List<int>, bool>(new List<int>(), true);
}





我的尝试:



编译错误异步方法的返回类型必须为void,任务或任务< t> ??

请帮帮我。

谢谢



What I have tried:

Compilation error "The return type of an async method must be void, Task or Task<t>" ??
Please help me out.
Thanks

推荐答案

异步返回一个简单的结果很痛苦。

以下代码编译:

Returning a simple result asynchronously is a pain.
Following code compiles:
public async Task<Tuple<List<int>, bool>> GetQuestionOptions(List<studs> studsList)
{
    var tmp = new Tuple<List<int>, bool>(new List<int>(), true);
    return await Task.FromResult(tmp);
}



魔法在返回await Task.FromResult


阅读: c# - 异步方法的返回类型必须为void,Task或Task& lt; T& gt; - 堆栈溢出 [ ^ ]


这篇关于如何返回任务&lt; tuple&lt; list&lt; int&gt ;, bool&gt; ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆