I parse in a file and save the results to a list in C#. I then parse all results of a DB query to another list. I want to compare the two lists for matches and save the results to another list to write an output file. I thought comparing the two lists was faster and better than running the query against the DB each time for each person since their is about 16k records in the file.
List 1. List fileList contains datatypes of: string personsName
List 2. List DBresults contains datatypes of: string personsName, string address, string phoneNumber
Trying to compare List 1 to List 2 to find matches and then send results to another list to write output.
Their could be multiple results per person in List 2 so I need to find every instance.
Started with a LINQ query like this but I’m no master at LINQ so I need some help.
var matches = fileList.Where(a=>a.personsName == DBResults.where(s=>s,personsName).toList();
I’m also open to other suggestions if you think you may have a faster way. I know IDctionarys and Hashtables are fast look up tables but I have three datatypes so I can’t do a keyvaluepair.
If I understand correctly your problem, the solution is the LINQ
Joinmethod.Or using the extension method syntax:
This method is extremely fast and internally uses HashSet to improve performances.