林克地图! 或收藏!
相当于 map 的 Linq 是什么? 或者 Ruby 中的collect! 方法?
a = [ "a", "b", "c", "d" ]
a.collect! {|x| x + "!" }
a #=> [ "a!", "b!", "c!", "d!" ]
我可以通过使用 foreach 迭代集合来做到这一点,但我想知道是否有更优雅的 Linq 解决方案。
What is the Linq equivalent to the map! or collect! method in Ruby?
a = [ "a", "b", "c", "d" ]
a.collect! {|x| x + "!" }
a #=> [ "a!", "b!", "c!", "d!" ]
I could do this by iterating over the collection with a foreach, but I was wondering if there was a more elegant Linq solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
地图 = 选择
Map = Select
高阶函数
map
最好用 Enumerable.Select 是 System.Linq 中的扩展方法。如果您好奇,其他高阶函数会像这样爆发:
reduce ->
Enumerable.Aggregate过滤器 ->
可枚举。哪里The higher-order function
map
is best represented in Enumerable.Select which is an extension method inSystem.Linq
.In case you are curious the other higher-order functions break out like this:
reduce ->
Enumerable.Aggregatefilter ->
Enumerable.Where