Accepted answer

in the first version you are creating an anonymous type with a single property named groupkey. anonymous types in c# use structural equality so the equality of the values comes down to the equality of the keys. this causes them to be properly grouped together.

in the second case you are using a custom type named groupingkey. it appears this uses the default or referential equality. hence none of the instances are considered equal and hence they get put into different groups.

Related Query