使用异步委托投影/λ [英] Projection using async delegate/lambda
问题描述
以下code不会编译针对异步CTP在Visual Studio 2010中:
The following code will not compile against the Async CTP in Visual Studio 2010:
Enumerable.Range(1, 5).Select(async x =>
{
await TaskEx.Delay(100);
return 5;
});
编译错误如下:
Test.cs(40,13): error CS1928: 'System.Collections.Generic.IEnumerable<int>' does not contain a definition for 'Select' and the best extension method overload 'System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>)' has some invalid arguments
Test.cs(40,49): error CS1503: Argument 2: cannot convert from 'lambda expression' to 'System.Func<int,int>'
不过,我读,应该会出现以下位置:
However, by my read, the following should occur here:
- 超载
的IEnumerable&LT; TResult&GT;选择&LT; TSource,TResult&GT;(这个IEnumerable的&LT; TSource&GT;源,Func键&LT; TSource,TResult&GT;选择器)。
应使用 - 作为
.Range(1,5)
是的IEnumerable&LT; INT&GT;
,TSource
是INT
- 制作拉姆达异步,服用
INT
并返回一个INT
应该产生一个任务&LT; INT方式&gt;
,这是TResult
应
- The overload
IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
should be used. - As the
.Range(1, 5)
isIEnumerable<int>
,TSource
isint
- Making the lambda async, taking an
int
and returning anint
should produce aTask<int>
, which is whatTResult
should be.
我没有看到一个语法的问题在这里。有什么问题?
请注意,由于我的主要应用程序需要Azure工具无法使用VS11呢。
Note that I cannot use VS11 yet because my main application requires Azure tools.
编辑:这正常工作与的MSBuild
在命令行,但不是在VS2010。看来,在命令行中,编译器VS11正在即使我针对.NET 4.0,而VS2010使用它自己的过程中的编译器使用。有谁知道如何换出了VS2010使用编译器?
This works fine with msbuild
at the command line, but not in VS2010. It seems that at the command line, the VS11 compiler is being used even though I'm targeting .NET 4.0, whereas VS2010 uses its own in-process compiler. Does anyone know how to swap out the compiler that VS2010 uses?
推荐答案
作品在我的LINQPad(在机器上安装VS11测试版)
Works in my LINQPad (VS11 Beta installed on the machine)
这篇关于使用异步委托投影/λ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!