I\'d like to sort a List
on element counts of IGrouping
s.
And that\'s it, the list should ideally be the same. I would compromise
Almost no operation in .NET clones an object. Neither deeply nor shallowly. LINQ also does not clone the elements it processes. Therefore, a simple LINQ query will work:
var oldList = ...;
var newList = (from x in oldList
group x by something into g
orderby g.Count()
from x in g //flatten the groups
select x).ToList();
This code copies references to the original objects. If you believe otherwise, you are probably misinterpreting what you are seeing.