===[ Loving The Lambda as Predicate| June 27th, 2009 ]
Old and busted:
public State FindByName(string name)
{
foreach(State thisState in this.StateList)
{
if (string.Compare(thisState.Name, name) == 0)
{
return thisState;
}
}
return null;
}
New Hotness:
public State FindByName(string name)
{
return States.Find(
state => (string.Compare(state.Name, name) == 0)
);
}
Sweet sweet syntactic sugar!