need help to write a linq query or a lambda expression

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
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
 
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
 
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
 
Back
Top