林克地图!或收集! [英] Linq Map! or Collect!
本文介绍了林克地图!或收集!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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!" ]
我可以通过用foreach遍历集合来执行此操作,但是我想知道是否有更优雅的Linq解决方案。
I could do this by iterating over the collection with a foreach, but I was wondering if there was a more elegant Linq solution.
推荐答案
地图=选择
var x = new string[] { "a", "b", "c", "d"}.Select(s => s+"!");
这篇关于林克地图!或收集!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文