【发布时间】:2013-01-14 14:39:38
【问题描述】:
不知何故,以下代码无法在 VS2010 中编译,但可以在 VS2012 中编译而无需更改。 VS2010 中的问题行是
names.Select(foo.GetName)
错误 CS1928: 'string[]' 不包含 'Select' 的定义和最佳扩展方法重载 'System.Linq.Enumerable.Select
(System.Collections.Generic.IEnumerable , System.Func )' 有一些无效参数。
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
var foo = new Foo();
var names = new[] {"Hello"};
Console.WriteLine(string.Join(", ", names.Select(foo.GetName)));
}
}
public class Foo
{
}
static class Extensions
{
public static string GetName(this Foo foo, string name)
{
return name;
}
}
}
【问题讨论】:
标签: c# .net visual-studio-2010 linq visual-studio-2012