c# - Calling .Distinct() on enumerables of enumerables -


at end of current linq query, have data in form of ienumerable<ienumerable<int>>, several duplicate combinations.

for example:

{   {5, 20}   {5, 20}   {10, 15} } 

what's best way filter these each set represented once? linq answer ideal can chain further.

if create sequence equality comparer this:

class sequenceequalitycomparer<t> : iequalitycomparer<ienumerable<t>> {     public bool equals(ienumerable<t> a, ienumerable<t> b) {         if (a == null) return b == null;         if (b == null) return false;         return a.sequenceequal(b);     }      public int gethashcode(ienumerable<t> val) {         return val.where(v => v != null)                 .aggregate(0, (h, v) => h ^ v.gethashcode());     } } 

then, can call .distinct(new sequenceequalitycomparer<int>()).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -