gpt4 book ai didi

c# - 推荐的 .NET 类用于唯一整数的集合?

转载 作者:太空狗 更新时间:2023-10-29 17:30:00 25 4
gpt4 key购买 nike

对于需要保留唯一整数列表的类,您有什么建议?

我想要将 Add() 整数添加到集合中并检查是否存在,例如包含()。

最好也将它们作为字符串显示在列表中,即。 “1、5、10、21”。

最佳答案

HashSet :

The HashSet<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...

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

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

A HashSet<T> collection is not sorted and cannot contain duplicate elements...

关于c# - 推荐的 .NET 类用于唯一整数的集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/163732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com