注意:使用 LINQ 连接解决了这个问题。
我需要比较源列表中的列表值是否存在于目标列表中,如果是,则将其保存到第三个列表。
我编写的代码确实有效,但它花费了很多时间,因为我的源列表有 30k 个项目,并且它将每个项目值与 1500 万个目标列表进行比较,这需要很多时间。因为它每次都会遍历整个列表(30k *1500 万次)
查看显然不是最佳但可以完成工作的代码。
// The below code will generate the lists from CSV file
The lists are below for sample
**Source List**
FileId FilePath FileChecksum
1 somepath A check1
2 somepath AA check2
3 somepath AAB check3
4 somepath B check4
5 somepath BB check5
**Destination List**
StepId StatusID JobId ProjectId FileId FilePath
5 6 4 2091 577206853 somepath A
5 6 4 2092 577206853 somepath AA
5 6 4 2093 577206853 somepath AAA
5 6 4 2094 577206853 somepath AB
5 6 4 2095 577206853 somepath A
5 6 4 2096 577206853 somepath B
5 6 4 2097 577206853 somepath BB
List<Source> SourceList = File.ReadAllLines(@"D:\source.csv").Skip(1).Select(v => Source.SourceFromCSv(v)).ToList();
List<Destination> DestinationList = File.ReadAllLines(@"D:\Destination.csv").Skip(1).Select(d => Destination.FromDestinationCSV(d)).ToList();
//This will compare and create a new list
var result1 =
from s in SourceList
from d in DestinationList
where (d.FilePath.ToLower() == s.FilePath.ToLower())
select (d.StepId + "," + d.StatusId + "," + d.JobId + "," +
d.ProjectId + "," + d.FileId + "," + d.FilePath + "," +
皈依舞
慕尼黑8549860
拉丁的传说
蝴蝶刀刀
互换的青春
相关分类