我想创建一个类,它使用HashSet<int>
来表示一个整数集。我希望它使用该内部容器跟踪哪些值包含在集合中。我到目前为止已经做到了这一点:使用HashSet <int>来创建一个整数集
class SetInteger
{
HashSet<int> intTest= new HashSet<int>();
intTest.Add(1);
intTest.Add(2);
intTest.Add(3);
intTest.Add(4);
intTest.Add(5);
intTest.Add(6);
intTest.Add(7);
intTest.Add(8);
intTest.Add(9);
intTest.Add(10);
}
所以,在这里我想我加入了一些值到HashSet
,但我没有看到这如何能保持跟踪包含在一套价值观。有任何想法吗?
'HashSet'也返回TRUE或'FALSE'在'.Add'方法告诉您该项目是否成功添加或它已经存在于集合中。 – Marc 2013-02-14 19:19:03