I have an IEnumerable object where Foo has a string property called 'Name'. Is there an easy LINQ statement that will let me return a collection of strings from that enumeration for those names?
e.g.
IEnumerable<Foo> (which contains...)
Foo.Name = First
Foo.Name = Second
Foo.Name = Third
I want to return an IEnumerable that contains 'First', 'Second开发者_运维知识库' and 'Third'
Howdoyadoozat?
If your initial IEnumerable is called list, this will do it:
list.Select(f => f.Name);
精彩评论