I\'m working on a Greatest Common Factor and Least Common Multiple assignment and I have to list the common factors. Intersection() won\'t work because that removes duplicat
Here's one way to do it. To be fair, it is very similar to David B's answer except that it uses a join to do the association.
IEnumerable seqA = ...
IEnumerable seqB = ...
var result = from aGroup in seqA.GroupBy(x => x)
join bGroup in seqB.GroupBy(x => x)
on aGroup.Key equals bGroup.Key
let smallerGroup = aGroup.Count() < bGroup.Count()
? aGroup : bGroup
from item in smallerGroup
select item;