You can make a separate call for the resulting values. This way you do not need to do this in the inner loop.
var y = factors.SelectMany(n => factors.Where(m => n < m).Select(m => n * m)).Distinct();
If factors = new[] { 2,3 }
you will get { 6 }
as the result. Also, if factors = new[] { 2,3,4,6 }
you get { 6,8,12,18,24 }
instead of { 6,8,12,12,18,24 }
. Please note if an additional 12
not obtained as a result.
source share