问题描述
我想另辟蹊径,短语,这将是有没有像列表℃的类;>
在C#中,但检查一个特定的值是否存在优化?我敢肯定的一个小组值列表与LT;>。载
可能会被罚款,但如果我有一组数以百万计值,并希望?找出某个值是否在其
I guess another way to phrase this would be "Is there a class like List<>
in C#, but optimized for checking whether a particular value is present?" I'm sure for a small set of values List<>.Contains
would probably be fine, but what if I have a set of thousands or millions of values and wanted to find out whether a certain value was in it?
我已经通过创建一个词典<实现这种在过去的事情,对象,诠释> ;
键,将其值设置为0每一个关键,但这种感觉真的沉闷。而现在有堆栈溢出,我的愚蠢的问题可以转化为教育千(几十个,偶数)。所以这里!
I've implemented this kind of thing in the past by creating a Dictionary<object, int>
and setting the value to 0 for every key, but this feels really clunky. And now there's Stack Overflow, where my stupid question can be transformed into education for thousands (dozens, even). So here it is!
我甚至不知道这样一类会被调用,也许比其他设置,所以很明显的话题一直搜索...具有挑战性的:)
I'm not even sure what such a class would be called, other than maybe Set, so obviously searches on the topic have been... challenging :)
推荐答案
尝试使用的类
Try using the HashSet<T>
class.
编辑:我花了很长很长的时间做你做了什么,直到我只是在这个类绊倒在阅读一个博客。
I spent a long long time doing exactly what you did until I just stumbled on this class while reading a blog.
这篇关于有没有像字典℃的类;>在C#中,但只是钥匙,没有价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!