group object with equal collections

Posted by Jeroen on Stack Overflow See other posts from Stack Overflow or by Jeroen
Published on 2010-05-26T18:50:57Z Indexed on 2010/05/27 4:51 UTC
Read the original article Hit count: 203

Filed under:

Hi,

Suppose 2 classes, Person and Pet. Each person has a collection of 1 or more pets. How do i group the Person in to a collection where they share the same pets.

Example:

Person 1: Cat, Dog, Spider

Person 2: Cat, Spider, Snake

Person 3: Dog

Person 4: Spider, Cat, Dog

Person 5: Dog

What i want as a result is this:

Group 1: Person 1, Person 4

Group 2: Person 3, Person 5

Group 3: Person 2

How do i achieve this using LINQ?

© Stack Overflow or respective owner

Related posts about linq-to-objects