tags:

views:

604

answers:

6

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

+1  A: 

Stealing from this question, it looks like you could use the Except<T>() method.

pix0r
+9  A: 

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);

You can replace the last parameter with an IEqualityComparer<string> of your choosing.

Jason
+6  A: 

With LINQ:

var missing = listA.Except(listB).ToList();
Marc Gravell
Nice. Similar to this: http://msdn.microsoft.com/en-us/library/bb397894.aspxI'm not used to dealing with large datasets, so is 100,000 easily handled this way?
Donaldinio
Sure; and if it isn't, you're going to have to work at the db, so C# is out anyway ;-p
Marc Gravell
+1  A: 
List<string> A = //get from file
List<string> B = //get from db

var C = A.Except(B);
Paul Creasey
A: 

Hi there,

If you are using SQL Server, then you might want to give a try to Volpet's Table Diff:

http://www.volpet.com/

You can try a fully-functional copy for 30 days.

Please let me know for anything.

Thank you,

Giammarco

Disclosure: I am the founder of Volpet Software.

Gia
A: 

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.

Michael Stum
No don't have to use List<string>. I will take a look at HashSet. Thanks!
Donaldinio