Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何求两个哈希集的补码_C#_Linq - Fatal编程技术网

C# 如何求两个哈希集的补码

C# 如何求两个哈希集的补码,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

我有两个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> 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)