c# - Get all combinatiion of Items of n number of lists -
this question has answer here:
- is there linq way cartesian product? 3 answers
- how can compute cartesian product iteratively? 4 answers
i have list contains further sub lists , have objects stored in sub list. want generate possible combinations of elements.
e.g. have list contains 2 list l1,l2 , have different objects stored in example l1 contains {obj1,obj2} l2 contains {obj3,obj4}
then result should come in form of
{obj1,obj3} {obj1,obj4} {obj2,obj3} {obj2,obj4}
all lists being generated dynamically. solution should generic irrespective of count of elements in main list , sub list
l1.selectmany(l1 => l2.select(l2 => tuple.create(l1, l2))).tolist();
Comments
Post a Comment