我有一个List<Customer>
,需要根据Customer.Name字段获取List<string>
。这是一个选择器UI。
如何查询List?
答案 0 :(得分:2)
快速测试(可能有问题)告诉我这有点快:
var customerNames = myCustomers.ConvertAll(c => c.Name);
至少这是做同样事情的另一种方式。
答案 1 :(得分:1)
试试这个:
List<string> names = custs.Select(x=>x.Name).ToList();
答案 2 :(得分:1)
var customerNames = myCustomers.Select( c=> c.Name).ToList();
答案 3 :(得分:0)
又一种语法......
var customerNames = (from c in myCustomers select c.Name).ToList();