C# 如何求两个哈希集的补码
我有两个hashset–setA和setBC# 如何求两个哈希集的补码,c#,linq,C#,Linq,我有两个hashset–setA和setB 我们怎样才能找到setA和setB的互补 交叉口代码是找到交叉口的最佳方法吗 代码 string stringA = "A,B,A,A"; string stringB = "C,A,B,D"; HashSet<string> setA = new HashSet<string>(stringA.Split(',').Select(t => t.Trim())); HashSet<string> se
string stringA = "A,B,A,A";
string stringB = "C,A,B,D";
HashSet<string> setA = new HashSet<string>(stringA.Split(',').Select(t => t.Trim()));
HashSet<string> setB = new HashSet<string>(stringB.Split(',').Select(t => t.Trim()));
//Intersection - Present in A and B
HashSet<string> intersectedSet = new HashSet<string>( setA.Intersect(setB));
//Complemenet - Present in A; but not present in B
stringA=“A,B,A,A”;
string stringB=“C,A,B,D”;
HashSet setA=newhashset(stringA.Split(',).Select(t=>t.Trim());
HashSet setB=newhashset(stringB.Split(',).Select(t=>t.Trim());
//交叉点-存在于A和B中
HashSet intersectedSet=新HashSet(setA.Intersect(setB));
//Complemenet-以一种形式存在;但在B中不存在
更新:
使用OrdinalIgnoreCase
忽略大小写敏感性
参考:
1-我们如何找到setA和setB的补码
使用
补充集将包含E
2-交叉口代码是找到交叉口的最佳方法吗
可能是的
1-我们如何找到setA和setB的补码
使用
补充集将包含E
2-交叉口代码是找到交叉口的最佳方法吗
很可能,是的您可以使用
除了
来获取A或B的补码。要获取对称补码,请使用对称性异常
setA.SymmetricExceptWith(setB);
请注意,这会修改setA。要获得交集,有两种方法:Intersect
,它创建一个新的哈希集
,和IntersectWith
,它修改第一个:
// setA and setB unchanged
HashSet<string> intersection = setA.Intersect(setB);
// setA gets modified and holds the result
setA.IntersectWith(setB);
//setA和setB未更改
HashSet intersection=setA.Intersect(setB);
//setA被修改并保存结果
刚毛与(立根)相交;
您可以使用Except
获取A或B的补码。要获取对称补码,请使用SymmetricExceptWith
setA.SymmetricExceptWith(setB);
请注意,这会修改setA。要获得交集,有两种方法:Intersect
,它创建一个新的哈希集
,和IntersectWith
,它修改第一个:
// setA and setB unchanged
HashSet<string> intersection = setA.Intersect(setB);
// setA gets modified and holds the result
setA.IntersectWith(setB);
//setA和setB未更改
HashSet intersection=setA.Intersect(setB);
//setA被修改并保存结果
刚毛与(立根)相交;
“我们怎样才能找到setA和setB的补码?”这不就是setA.除了(setB)
?“我们怎样才能找到setA和setB的补码?”这不就是setA.除了(setB)
?