开发者

Linq: Getting a List<String> from List<Customer> based on customer.name

I have a List<Customer> and need to get a List<string> based on the Customer.Name field. This is for a picker UI开发者_如何学Python.

How can I query a List for that?


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.


Try this:

List<string> names = custs.Select(x=>x.Name).ToList();


var customerNames = myCustomers.Select( c=> c.Name).ToList();


Yet another syntax...

var customerNames = (from c in myCustomers select c.Name).ToList();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜