小编PCH*_*PCH的帖子

结果与ContinueWith之间的C#差异

这两种似乎做同样事情的方法有什么区别?即使使用async/await也可以完成吗?

public Task<int> TaskMaxAsync1 ( Task<int>[] my_ints )
{
    return Task.WhenAll( my_ints )
    .ContinueWith ( x => x.Result.Where ( i => i%2 != 0 ).Max( ) ) ;
}

public Task<int> TaskMaxAsync2 ( Task<int>[] my_ints )
{
    var numbers = Task.WhenAll( my_ints ).Result ;
    return Task.FromResult( numbers.Where( i => i%2 != 0 ).Max( ) ) ;
}
Run Code Online (Sandbox Code Playgroud)

c# asynchronous task-parallel-library async-await

9
推荐指数
2
解决办法
319
查看次数