Not completely sure how I can phrase this question best. How can I compare each element of a list with each elements of the same list only once.
For instance:
var textlist = ["a", "b", "c"];
var intersecting = from string a in textlist
from string b in textlist
where a != b && a.SomeCondition(b)
select new
{
object1 = a,
object2 = b
};
Assuming “a” gives ‘True’ to “SomeCondition” with “b”, I want the final result to be:
[["a, b"]]
Whereas now it would be:
[["a, b"], ["b, a"]]
Is this possible with a Linq Query?
One way is to compare each element to just the elements located after it:
Note: This solution, along with most solutions to this problem that use LINQ, will be horribly inefficient if used on an IEnumerable that is expensive to enumerate.