开发者

dynamic nested looping

开发者 https://www.devze.com 2023-03-25 05:31 出处:网络
I have a list of objects dynamically created. MyObject is a custom object consisting of List of Items. So for exa开发者_开发百科mple :

I have a list of objects dynamically created. MyObject is a custom object consisting of List of Items. So for exa开发者_开发百科mple :

MyObject Instance1 has { a, b }

MyObject Instance2 has { x, y, z}

MyObject Instance3 has { 1, 2, 4, 5 }

...............

..............

MyObject InstanceN has { n1, n2 ............}

I want to be able to use either recursion or an iterative approach to solve the problem of generating all unique combinations.

How do I generate all unique combinations .. an output like this

{a, x, 1,......., n1}
{a, x, 1,......., n2}
{a, x, 2,......., n1}
{a, x, 2,......., n2}


What you're looking for is the Cartesian Product, and Eric Lippert has written an excellent blog post, with sample code for how to do this in LINQ, that you can probably adapt.

You can also look at this question, which is similarly related.

0

精彩评论

暂无评论...
验证码 换一张
取 消