Could someone tell me what the difference / advantage is between the following 3 Find options:
List<Employee> Employees = new List<Employee>();
Employee tmp = new Employee();
tmp.FirstName = "Randy";
tmp.LastName = "Jones";
Employees.Add(tmp);
tmp.FirstName = "David";
tmp.LastName = "Smith";
Employees.Add(tmp);
tmp.FirstName = "Michele";
tmp.LastName = "Morris";
Employees.Add(tmp);
// Find option 1
Employee eFound1= Employees.Find((Employee emp1) => {return emp1.LastName == "Jones";});
// Find option 2
Employee eFound2 = Employees.Find(emp2 => emp2.LastName == "Smith");
// Find option 3
Employee eFound3 = Employees.Find(
delegate(Employee emp3)
{
return emp3.LastName == "Morris";
}
);
I have been reading about lambdas and predicates (which I suspect is somehow tied to the answer) but I can't put it all together. Any enlightenment would be appreciated!
Thanks David
The first is a statement lambda, the second one is a lambda expression and the third is an anonymous method.
They are all functionally equivalent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With