LINQ扩展SelectMany在3.5对4.0?

Mob*_*erg 8 c# linq

当我在这里看到达林斯的建议时......

IEnumerable<Process> processes = 
    new[] { "process1", "process2" } 
    .SelectMany(Process.GetProcessesByName);
Run Code Online (Sandbox Code Playgroud)

(process.getprocessesbyname())

..我有点好奇,我在VS2008中尝试使用.NET 3.5 - 它没有编译,除非我将其更改为..

IEnumerable<Process> res = 
  new string[] { "notepad", "firefox", "outlook" }
    .SelectMany(s => Process.GetProcessesByName(s));
Run Code Online (Sandbox Code Playgroud)

在我怀疑是我的问题之前阅读了一些Darins的答案,当我后来在.NET 4.0上使用.NET 4.0时 - 正如预期的那样 - 最初的建议很有效.

我的问题是:从3.5到4.0发生了什么使得这种(新语法)成为可能?它是扩展(hmm)扩展方法还是lambda语法的新规则?

Mat*_*ted 7

似乎在新版本的C#(C#4.0与C#3.0 ......不是.NET的版本)中,委托选择更加智能化.这个想法在VS2008中可用,但它在解决哪个版本的问题时遇到了问题有多个重载时使用的方法.在编译时选择该方法,因此我必须相信这与更新的编译器有关,而不是与.NET的版本有关.您可能会发现,您可以在VS2010中为.NET 2.0编译的解决方案中使用新的重载功能.

例如,这适用于VS2008

var ret = new[] { "Hello", "World", "!!!" }.Aggregate(Path.Combine);
// this is the value of ret => Hello\World\!!!
Run Code Online (Sandbox Code Playgroud)