HashSet<T>类
HashSet
1、HashSet
2、HashSet
构造方法:
HashSet() 默认相等比较器创建一个空的新实例。
HashSet(IEnumerable
HashSet(IEqualityComparer
HashSet(IEnumerable
因为HashSet
以下给出它的一些常用方法介绍
成员 类型 说明
Add 方法 将指定的元素添加到集合中
Clear 方法 清空集合中的所有元素
Contains 方法 确定某元素是否在HashSet
Exists 方法 确定HashSet
ExceptWith 方法 从当前HashSet
IntersectWith 方法 修改当前的HashSet
IsProperSubsetOf 方法 确定HashSet
IsProperSupersetOf 方法 确定HashSet
IsSunsetOf 方法 确定HashSet
IsSupersetOf 方法 确定HashSet
Remove 方法 从HashSet
RemoveWhere 方法 从HashSet
SetEquals 方法 确定HashSet
SynmmetricExceptWith 方法 修改当前的HashSet
TrimExcess 方法 将HashSet
UnionWith 方法 修改当前的HashSet
给个简单的例子,写不完的,总之记得HashSet
static void Main(string[] args) { HashSet<string> hs = new HashSet<string>(); hs.Add("你"); hs.Add("好"); hs.Add("吗"); HashSet<string> hs1 = new HashSet<string>(); hs1.Add("你"); hs1.Add("好"); bool b = hs1.IsProperSubsetOf(hs); //确定hs1是否是hs的真子集 Console.WriteLine(b); //输出True HashSet<string> hs2 = new HashSet<string>(); hs2.Add("爱你"); IEnumerable<string> list = hs.Union(hs2); //返回并集 foreach (string str in list) { Console.WriteLine(str); //输出 你 好 吗 爱你 } Console.ReadKey(); }
输出: