[英]async/await: Cannot implicitly convert type 'void' to 'int[]'
I am using C# 7.1 and below async/await code give me error, Cannot implicitly convert type 'void' to 'int[]'
我正在使用C#7.1及以下异步/等待代码给我错误,
Cannot implicitly convert type 'void' to 'int[]'
What is the solution for it? 有什么解决方案?
static async Task Main(string[] args)
{
Task task1 = Task.FromResult(3);
Task task2 = Task.FromResult(5);
Task task3 = Task.FromResult(7);
int[] results = await Task.WhenAll(task1, task2, task3);
Console.ReadLine();
}
I want to return result like 我想返回结果像
// "results" contains { 3, 5, 7 }
Here's how it must be: 必须这样:
Task<int> task1 = Task.FromResult(3);
Task<int> task2 = Task.FromResult(5);
Task<int> task3 = Task.FromResult(7);
int[] results = await Task.WhenAll(task1, task2, task3);
You were casting Task<int>
to base type Task
. 你被铸造
Task<int>
碱基类型Task
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.