http://msdn2.microsoft.com/en-us/vcsharp/bb264519.aspx
Take the initial uneffecient example:
// First attempt:
public List
{
IEnumerable
List
foreach ( PhoneBookEntry ph in newYorkNumbers)
{
string name = string.Format(“{0} {1}”, ph.FirstName,
ph.LastName);
if ( RecognizePerson( name ) )
peopleIKnow.Add(name);
}
return peopleIKnow;
}
// Fifth attempt:public
IEnumerable
PeopleIKnowInNewYork()
{
IEnumerablenewYorkNumbers =
PhoneBook.FindListFor(“New York”);
IEnumerablenames = Transform (newYorkNumbers,
delegate(PhoneEntry entry)
{
return string.Format(“{0} {1}”, entry.FirstName, entry.LastName);
});
return Filter(names,
delegate(string name)
{
return RecognizePerson(name);
}
);
}
No comments:
Post a Comment