I have Class as defined below
class Employee
{
public int EmpNo{get;set;}
public string Name{get;set;}
public string Designation{get;set;}
}
and I have a list of employees
List<Employee>
I can find a list of employees with similar designation, using FindAll() method.
But I want to have a list(or array) of EmpNo and not list of Employees. I can use a for loop to construct, but want a different answer using predicate. How can I do it? or is it not possible? I think had got a solution for similar problem earlier, but not getting it now.
May be Something like FindAll(…).ToArray().
EDIT
Ok I got the answer.
FindAll(emp => emp.Designation.Equals("Executive")).Select(item => item.EmpNo).ToArray()
The alternative is;
There are slight performance differences between FindAll and Where, have a look at this;
FindAll vs Where extension-method