c# - How does Distinct() work on a List<> of anonymous type? -


this question has answer here:

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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -