I have composed a cartesian product (A×A) via Linq and removing the reflexive elements is pretty easy (a != b), but I struggle with the symmtric elements. Any suggestions? Thx
from var a in Stuff
from var b in Stuff
where a != b
where // Remove symmetric Elements
select new { A = a, B = b}
This Query contains the cartesion product over Stuff without the reflexive elements ( (a,a), (b,b) and so on). The symmetic elements are still in it ( (a,b) and (b,a) ).
You could index your source enumeration by projecting to an anonymous type that keeps the index of the element and then use the index to remove the symmetrical elements in your cross join:
This has the advantage that it works on any source enumeration, items do not need to be comparable.