In C# i need to get all values of a particular property from an object list into list of string
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
I am familiar with the foreach method to extract the value but I want to know if \ how its possible use linq or IENumerable functions or some shorter code to extract values from the list object property values into a string object.
My query is Similar to C# select elements from IList but i want the the result as list of string
List<string> empnames = (from e in emplist select e.Enaame).ToList();
Or
string[] empnames = (from e in emplist select e.Enaame).ToArray();
Etc...
Source: Stackoverflow.com