Alex Rivera | Logout

Linq Map! or Collect!

Asked 2009-03-31T17:23:19.240
25

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.

Edit
Report

1 Answer

36

Map = Select

var x = new string[] { "a", "b", "c", "d"}.Select(s => s+"!");
answered 2009-03-31T17:25:37.643

Your Answer