c# - How does Distinct() work on a List<> of anonymous type? -
this question has answer here:
- linq select distinct anonymous types 7 answers
how distinct() work on list<> of anonymous type? property compare? or return same list?
example:
list<someobject> list; .... .... var result = list .where(i => i.condition) .select(i => new { name = i.name, date = i.date }); .distinct() .tolist()
please note applied distinct on anonymous-type list.
from msdn
because equals , gethashcode methods on anonymous types defined in terms of equals , gethashcode methods of properties, 2 instances of same anonymous type equal if properties equal.
Comments
Post a Comment