Monday, March 23, 2009

Codes example for why use Lambda

Consider this example:
 string person = people.Find(person => person.Contains("Joe"));

versus
 public string FindPerson(string nameContains, List<string> persons)
 
{
     
foreach (string person in persons)
         
if (person.Contains(nameContains))
             
return person;
     
return null;
 
}