请问C#哪个集合可以不保存重复的元素?

MicFreeBSD 2009-06-09 10:15:37
java里的有一个Set的功能可以实现我的这个需求,不知道C#有没有类似的集合? 如果没有的话怎么可以实现这个功能呢?
...全文
1190 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
stan0714 2009-06-09
  • 打赏
  • 举报
回复
我所给的算法在2.0,3.0 框架中通用。

当然在3.0 中可以使用linq来做更简单~~~
stan0714 2009-06-09
  • 打赏
  • 举报
回复
没有这个集合~~~~

要自己写一个算法:
算法思路如下:目标集合A
1.定义一个源集合B,
2.让后往B 中添加A 的元素
需要判定
foreach(string str in A)
{
if(B.Contains(str))
continue;
else
B.Add(str);
}
3.返回B ,就是自己所需的。
vwxyzh 2009-06-09
  • 打赏
  • 举报
回复
3.5的HashSet<T>
wartim 2009-06-09
  • 打赏
  • 举报
回复 1
一个老外他自己对于c++ STL容器的c#的等同物的看法

I generally use the following to replicate similar data structures from the STL.
std::vector - List<T>
std::list - LinkedList<T>
std::map - Dictionary<Tkey, Tvalue>
std::set - Dictionary<Tkey, Tvalue> (with null values)
std::multimap - Dictionary<Tkey, List<Tvalue>>
std::multiset - Dictionary<Tkey, int> (with int keeping count of the number of Tkeys)

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧