开发者

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

开发者 https://www.devze.com 2023-01-30 08:59 出处:网络
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?

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

精彩评论

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