I have a large list (~ 110,000 strings), which I need to compare to a similar sized list.
List A comes from 1 system. List B comes from a SQL table (I can only read, no stored procs, etc)
What is the best way to find what values are in list A, that no longer exists in list B?
Is 100,000 strings a large number to be handled in an array?
thanks
So you have two lists like so:
List<string> listA;
List<string> listB;
Then use Enumerable.Except
:
List<string> except = listA.Except(listB).ToList();
Note that if you want to, say, ignore case:
List<string> except = listA.Except(listB, StringComparer.OrdinalIgnoreCase).ToList();
You can replace the last parameter with an IEqualityComparer<string>
of your choosing.
With LINQ:
var missing = listA.Except(listB).ToList();
Out of interest, do you HAVE to use List<string>
? Because in .net 3.5 SP1, you can use the HashSet and it's ExceptWith method. To my understanding, HashSets are specifically optimized for comparisons between two Sets.
List<string> A = //get from file
List<string> B = //get from db
var C = A.Except(B);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With