题
什么是LINQ的等同于地图!或收集!方法在红宝石?
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 -> href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.aggregate.aspx" rel="noreferrer"> Enumerable.Aggregate
filter ->
Enumerable.Where
不隶属于 StackOverflow