考虑两个自定义Record
对象的集合。搜索这些匹配项的有效方法是什么?为了弄清楚“匹配”的含义:这些对象实例的每个属性都相等(它们只是字符串)。
首先将它们放入两个List<Record>
中。然后:
foreach (Record record1 in List1<Record>)
{
foreach (Record record2 in List2<Record>)
{
// assume there is a match() method implemented which compares two Record objects
if (match(record1,record2))
{
// write it to the console, add it to a list of matches, or other appropriate action
}
}
}
请注意,这些对象的顺序无关紧要。