Linq地图! 还是收集!

什么是Linq相当于地图! 或收集! Ruby中的方法?

a = [ "a", "b", "c", "d" ] a.collect! {|x| x + "!" } a #=> [ "a!", "b!", "c!", "d!" ] 

可以通过使用foreach迭代集合完成此操作,但我想知道是否有更优雅的Linq解决方案。

地图=选择

 var x = new string[] { "a", "b", "c", "d"}.Select(s => s+"!"); 

高阶函数map最好用Enumerable.Select表示,它是System.Linq的扩展方法。

如果你很好奇,其他更高阶的函数就像这样:

reduce -> Enumerable.Aggregate
filter -> Enumerable.Where

Interesting Posts