I know how it’s possible to use anonymous types to group by a fixed list of values. What I want to do is group by an actual set of values.
For example, the result of this expression is 2.
new List<HashSet<int>> {
new HashSet<int> { 4 },
new HashSet<int> { 4 }
}.GroupBy (x => x).Count()
I’m looking for a way to put those sets in the same group so that the result would be 1. In python, this would be accomplished using frozenset.
What’s the cleanest way of doing this?
You can use the static
HashSet<T>.CreateSetComparermethod for this purpose.