Reputation: 68800
I have a List<Customer>
and need to get a List<string>
based on the Customer.Name field. This is for a picker UI.
How can I query a List for that?
Upvotes: 0
Views: 222
Reputation: 103
Yet another syntax...
var customerNames = (from c in myCustomers select c.Name).ToList();
Upvotes: 0
Reputation: 4584
A quick test (which may be faulty) tells me this is a bit faster:
var customerNames = myCustomers.ConvertAll(c => c.Name);
At least it's another way to do the same thing.
Upvotes: 2
Reputation: 160982
var customerNames = myCustomers.Select( c=> c.Name).ToList();
Upvotes: 1
Reputation: 100607
Try this:
List<string> names = custs.Select(x=>x.Name).ToList();
Upvotes: 1