我正在对两个文件(新旧文件)中的数据进行比较。除了新文件具有已更改的旧文件中的项目外,其他文件都是相似的。我需要将已更改的项添加到已更改的列表中,将未更改的项添加到未更改的列表中。为此,我从旧文件中的新文件中搜索每一项,并比较文件元素。如果找到新项目,则将其添加到未更改列表中,否则将其添加到已更改列表中。
我现在正在尝试确定的是新文件中的哪一项发生了更改。如果找不到该项目,我如何确定?此外,新文件中的多个元素可能与旧文件不同。
下面是代码片段:
foreach (var newfileItem in NewFile)
{
var checkitem = OldFile.FirstOrDefault(d => d.fileID == newfileItem.fileID && d.SysName == newfileItem.Sysname && d.SysCount == newfileItem.SysCount);
if (checkitem == null) //item not found therefore something changed
{
//which item changed??
changedlist.Add(checkitem);
}
else //item found, therefore unchanged
{
unchangedlist.Add(newfileItem);
}
checkitem = null;
}
https://stackoverflow.com/questions/51866674
复制相似问题