I have an ICollection
of Thing
. Thing
has a string
property Name
. I would like to get an array of all Name
in my ICollection
. I know I can do this by iterating over the collection and building the array, but is there a neater way to do this with lambda notation?
Take the 2-minute tour
×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
|
||||
|
Sure, LINQ lets you do this very easily:
Of course if you're just going to iterate over it, you don't need the
Or you could create a
In all of these cases you could use Using EDIT: Now we know you really do need an array, it would be slightly more efficient to do this yourself with a manual loop, as you know the size beforehand. I'd definitely use the first form until I knew it was a problem though :) |
|||||||||
|