可以使用Except()函数比较两个哈希集合列表。下面是一个包含代码示例的解决方法:
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
// 创建两个哈希集合列表
var list1 = new List>()
{
new HashSet { 1, 2, 3 },
new HashSet { 4, 5, 6 },
new HashSet { 7, 8, 9 }
};
var list2 = new List>()
{
new HashSet { 1, 2, 3 },
new HashSet { 4, 5, 6 },
new HashSet { 10, 11, 12 }
};
// 使用Except()函数比较两个列表
var difference = list1.Except(list2).ToList();
// 输出差异结果
Console.WriteLine("差异结果:");
foreach (var hashSet in difference)
{
Console.WriteLine(string.Join(", ", hashSet));
}
Console.ReadLine();
}
}
上面的代码示例创建了两个哈希集合列表 list1
和 list2
。然后使用Except()函数比较这两个列表,并将差异结果存储在 difference
变量中。最后,通过遍历差异结果输出每个哈希集合的内容。
下一篇:比较两个哈希图的哈希图