need help to write a linq query or a lambda expression

T

Tony Johansson

Hello!

I have a collection of objects. These objects contain several different
fields. One of these fields is named id and is of type string.
In the collection there are many objects that have the same id and there are
also some objects that have unique id.
The collection is called result. The objects in the collection consist of
WorksheetRowParameter.

What I want is to write a linq query or a lambda expression that give me all
the id's that are unique which mean there are nu duplicate.

For example assume you have these objects.
One object has id = 5
One object has id = 11
One object has id = 15
Six object has id = 3
Five object has id = 9
Three object has id = 7

In this case I want to receive id 5,11 and 15 because these don't have
duplicate.

//Tony
 
M

miher

Hi,

Try this :
YourCollection.GroupBy(i => i.ID).Where(i => i.Count() == 1).Select(i =>
i.First().ID);
(It might not be as effective as that You could write by hand.)

Hope You find this useful.
-Zsolt
 
M

miher

Hi,

Try this :
YourCollection.GroupBy(i => i.ID).Where(i => i.Count() == 1).Select(i
=>i.First().ID);
(It might not be as effective as that You could write by hand.)

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