3.5 VS 4.0 LINQ延伸的SelectMany? [英] LINQ extention SelectMany in 3.5 vs 4.0?

查看:113
本文介绍了3.5 VS 4.0 LINQ延伸的SelectMany?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我看到Darins建议在这里..

When I saw Darins suggestion here ..

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



http://stackoverflow.com/questions/3059667/process-getprocessesbyname/3059733#3059733

..我是一个有点好奇,我试图在VS2008与.NET 3.5 - 并没有编译,除非我改成了..

.. I was a bit intrigued and I tried it in VS2008 with .NET 3.5 - and it did not compiling unless I changed it to ..

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



看了一些Darins答案之前,我怀疑这是我,是这个问题,后来当我。拿到我的手在VS2010 with.NET 4.0 - 预期 - 原建议的工作精美

Having read some Darins answers before I suspected that it was me that were the problem, and when I later got my hands on a VS2010 with.NET 4.0 - as expected - the original suggestion worked beautifully.

我的问题是:什么都从3.5 happend到4.0,使这个(新的语法)可能吗?是不是已经扩展extentionmethods(HMM)或新的规则,lambda语法还是?我试图寻找,但我的谷歌福不够强。

My question is : What have happend from 3.5 to 4.0 that makes this (new syntax) possible? Is it the extentionmethods that have been extended(hmm) or new rules for lambda syntax or? I've tried to search but my google-fu was not strong enough.

请原谅如果问题是有点幼稚,请注意,我已经功能标签作为初学者:)

Please forgive if the question is a bit naive and note that I've taged it as beginner :)

推荐答案

这似乎代表选择是C#的新版本更加智能(C#4.0与C#3.0 ...不是.NET版本。)这个想法是在VS2008中可用,但它有解决问题的时候有多个重载使用哪个版本的方法。该方法在编译时选择的,所以我相信这比使用.NET版本的更多的是更新的编译器。你可能会发现,你可以使用在VS2010编译的.NET 2.0解决方案新的过载能力。

It seems that the delegate selection is much more intelligent in the new version of C# (C# 4.0 vs. C# 3.0... not the version of .NET.) This idea was available in VS2008, but it had problems resolving which version of the method to use when there were multiple overloads. The method is selected at compilation, so I have to believe that this has more to do with the updated compiler than with the version of .NET. You will probably find that you can use the new overload ability with solutions compiled for .NET 2.0 in VS2010.

例如,这部作品在VS2008

For example, this works in VS2008

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

这篇关于3.5 VS 4.0 LINQ延伸的SelectMany?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆