Before Lambda:
List<Person> result = GetFromSomeWhere();
List<string> distinctids= new List<string>();
foreach (Person one in result)
{
if (!distinctids.Contains(one .Id.ToString()))
distinctids.Add(one .Id.ToString());
}
foreach (string id in distinctids)
{
DisplayPerson(id);
}
After:
List<Person> result = GetFromSomeWhere();
var result = result.Select(p=> p.Id).Distinct().ToList() ;
result.ForEach(id=>DisplayPerson(id));
No comments:
Post a Comment