C#集合集合? [英] C# Set collection?

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

问题描述

有谁知道在 C# 中是否有一个很好的等效于 Java 的 Set 集合?我知道您可以通过填充但忽略值来使用 DictionaryHashTable 来模拟集合,但这不是一种非常优雅的方式.

Does anyone know if there is a good equivalent to Java's Set collection in C#? I know that you can somewhat mimic a set using a Dictionary or a HashTable by populating but ignoring the values, but that's not a very elegant way.

推荐答案

尝试 HashSet:

HashSet(Of T) 类提供高性能的集合操作.集合是不包含重复元素的集合,并且其元素没有特定的顺序......

The HashSet(Of T) class provides high-performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order...

HashSet(Of T) 对象的容量是该对象可以容纳的元素数.HashSet(Of T) 对象的容量会随着元素添加到对象中而自动增加.

The capacity of a HashSet(Of T) object is the number of elements that the object can hold. A HashSet(Of T) object's capacity automatically increases as elements are added to the object.

HashSet(Of T) 类基于数学集合模型,并提供类似于访问 Dictionary(Of TKey, TValue)Hashtable 集合.简单来说,HashSet(Of T) 类可以被认为是一个字典(Of TKey, TValue) 没有值的集合.

The HashSet(Of T) class is based on the model of mathematical sets and provides high-performance set operations similar to accessing the keys of the Dictionary(Of TKey, TValue) or Hashtable collections. In simple terms, the HashSet(Of T) class can be thought of as a Dictionary(Of TKey, TValue) collection without values.

HashSet(Of T) 集合未排序且不能包含重复元素...

A HashSet(Of T) collection is not sorted and cannot contain duplicate elements...

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

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