C#如何创建一组集合 [英] C# How to I create a set of sets

查看:54
本文介绍了C#如何创建一组集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一组(int)集合

I want to create a set of sets (of int)

类似:

SortedSet<SortedSet<int>>

HashSet<HashSet<int>>

但是在尝试匹配集合时,它使用 ReferenceEquals 进行比较

but when trying to match the sets it uses ReferenceEquals to compare

因此对我的目的毫无用处

and thus is useless for my purpose

有没有办法让一组集合在 C# 中有用?

is there a way to make a set of sets useful in C#?

推荐答案

您需要通过 HashSet.CreateSetComparer() 到外部集合以通过引用进行比较.

You need to pass HashSet<int>.CreateSetComparer() to the outer set to compare by reference.

这篇关于C#如何创建一组集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆