开发者

Convert a collection of objects with a string property to an enumeration of those strings using LINQ

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜