在C#中,我可以写:
Enumerable.Range(1, 20).Select(i => i)
我还可以明确指定Select
的两个类型参数:
Enumerable.Range(1, 20).Select<int, int>(i => i)
在VB中,第一个代码段的等效工作正常:
Enumerable.Range(1, 20).Select(Function(i) i)
但是当我尝试指定类型参数时,它会失败:
Enumerable.Range(1, 20).Select(Of Integer, Integer)(Function(i) i)
我得到的错误是:
BC32087重载解析失败,因为没有可访问的'[Select]'接受此数量的类型参数。
我不明白:有an overload of extension method named Select
with two type parameters。我做错了什么?
答案 0 :(得分:4)
尝试一下:
Enumerable.Range(1, 20).Select(Of Integer)(Function(i) i)
您之前的示例无法正常工作的原因是因为the overload that you referenced实际上是Enumerable
个对象的扩展方法,因此第一个参数实际上是触发调用的对象。 / p>