I
I
iRumba2015-08-14 10:35:46
.NET
iRumba, 2015-08-14 10:35:46

How to convert a collection of objects to a collection of the values ​​of one of its properties in one line?

for example, there is a List, and I need to get the List from the values ​​of its Text property. How to do it in one line? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2015-08-14
@iRumba

source.Select(c=>с.Text).ToList() 
или
var t = from c in source
           select c.Text

Basically the same

P
pixik, 2015-08-14
@pixik

I don’t know from ready-made tools, but it would be possible to finish the standard List a little to the desired functionality and already use it in one line.
To get something like: var XXXFieldList = mySuperlist.ToXXXFieldList();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question