Mar*_*ers 28
你试过Enumerable.Except吗?
setB.Except(setA)
Run Code Online (Sandbox Code Playgroud)
例:
HashSet<int> setB = new HashSet<int> { 1, 2, 3, 4, 5 };
HashSet<int> setA = new HashSet<int> { 1, 3, 5, 7 };
HashSet<int> result = new HashSet<int>(setB.Except(setA));
foreach (int x in result)
Console.WriteLine(x);
Run Code Online (Sandbox Code Playgroud)
结果:
2 4