如何:
var results = localDetails.Join(remoteDetails,
lf => lf.RelativeFilePath,
rf => rf.RelativeFilePath,
(lf, rf) => lf.ModifyDate > rf.ModifyDate ? lf : rf);
這符根據每個列表(因此這兩個鍵選擇器)的相對文件路徑上的兩個列表,然後兩人的「結果」,它採用一個具有更大的ModifyDate。
剛剛測試這對一些樣本數據(根據您的描述)和它的作品,例如,如果您有:
var localDetails = new List<SyncFile>
{
new SyncFile { ModifyDate = DateTime.Now, RelativeFilePath = "c:\\help", Id = 1 },
new SyncFile { ModifyDate = DateTime.Now.AddDays(1), RelativeFilePath = "c:\\wow", Id = 2 },
new SyncFile { ModifyDate = DateTime.Now, RelativeFilePath = "c:\\y", Id = 6 },
};
var remoteDetails = new List<SyncFile>()
{
new SyncFile { ModifyDate = DateTime.Now.AddDays(-1), RelativeFilePath = "c:\\help", Id = 3 },
new SyncFile { ModifyDate = DateTime.Now.AddDays(5), RelativeFilePath = "c:\\wow", Id = 4 },
new SyncFile { ModifyDate = DateTime.Now, RelativeFilePath = "c:\\x", Id = 5 },
};
var results = localDetails.Join(remoteDetails, l => l.RelativeFilePath, r => r.RelativeFilePath, (lf, rf) => lf.ModifyDate > rf.ModifyDate ? lf : rf);
foreach(var result in results)
{
Console.WriteLine(result.Id);
}
輸出將是ID爲1和4(我剛添加的ID,這樣我會知道哪些是測試目的)。
發佈您試圖執行的代碼。也許我們可以指出你的錯誤,而不是給你解決方案_as is_。你不應該遠離解決方案。 – Otiel