need help with a linq query

T

Tony Johansson

Hello
I have two collections with objects lets call these collection A and B.
These two collections have a fileld name ID of type string in common.
Note this ID is always numeric.

So assume you have 7 objects in collection A. Each of these objects have
different ID. These 7 object have the following ID
7, 9,17,19,27,29,37.
In collection A you have never duplicate on any ID.

Collection B have 15 objects and each object have only one ID as collection
A have.
The 16 objects have the following ID 9,19,29,39,47.
So in my case
ID 9 exist 3 times
ID 19 exist 3 times
ID 29 exist 4 times
ID 39 exist 3 times
ID 47 exist 3 times

So now to my question how do I write a linq query that give me the ID that
only exist in collection A but not in collection B.
In my case I want a linq query that would give me the ID 7,17,27 and 37

//Tony
 
M

miher

Hi,

I think You looking for something like this:
A.Select(i => i.ID).Except(B.Select(i=>i.ID))

Hope You find this useful.
-Zsolt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top