【发布时间】:2012-03-27 08:22:13
【问题描述】:
在 C# 中,我需要将特定属性的所有值从对象列表中获取到字符串列表中
List<Employee> emplist = new List<Employee>()
{
new Employee{ EID=10, Ename="John"},
new Employee{ EID=11, Ename="Adam"},
new Employee{ EID=12, Ename="Ram"}
};
List<string> empnames = emplist.//get all Enames in 'emplist' object into list
//using linq or list functions or IENumerable functions
我熟悉提取值的 foreach 方法,但我想知道 如果\它可能如何使用 linq 或 IENumerable 函数或一些较短的代码从列表对象属性值中提取值到一个字符串对象。
我的查询类似于C# select elements from IList,但我希望结果为字符串列表
【问题讨论】: