Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个很大的列表,其中列出了某些类型的对象Order。此外,我已经定义了一个IEqualityComparer<Order>并且我的目标是有效地创建一个列表(或分组)列表,其中每个子列表都包含彼此相等的对象。从数学上讲,我有一个等价关系(IEqualityComparer),并且想要一个所有等价类的列表。我考虑过使用HashSet<Order>,Dictionary<>或者Lookup<>但它们似乎不适合我的情况。那么有什么想法吗?
Order
IEqualityComparer<Order>
HashSet<Order>
Dictionary<>
Lookup<>
我认为这对工作来说是这样的:
var uniqueItems = yourRawList.Distinct(yourComparer); var result = uniqueItems.Select(i => new List<Order>(yourRawList.Where(o =>yourComparer.Equals(i, o))));