Now above example has 5 static arrays shape, size, type, top, msg and above code shows every combination is possible between these arrays. Like

Round Round - 7

Round - 7 - Chocolate

like this all possible combination.

Screenshot :

Currently I have static arrays shape, size, type, etc.. So I am manually writing foreach loop for each array inside upper array.

Now suppose these arrays comes dynamically. I Don't know count the will be for example sometimes it must be shape and size some time its must be shape, size and type, and sometime they are completely different.

Re: Create dynamic foreach loop for sequential search type in C#

Thank you very much for you reply and your efforts. Currently the example is about cakes. These Shape, Size, Type array is not static. The all are comes fro DB. I event don't know what will come but when arrays will come I want to take each and every possible
combination. Like

Round

Round - 7

Round - 7 - Chocolate

So my ultimate aim is I don't how many arrays will come so I don't know how many times I have to foreach. So I want dynamic foreach loop as per the count of arrays.

Re: Create dynamic foreach loop for sequential search type in C#

According to your description, I suggest you could create a string array List and add the string array into this list, then, you can try to use recursive method to loop through the list and string array, and get the value.

Best regards,
Dillion

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Re: Create dynamic foreach loop for sequential search type in C#

Thank you very much for you reply and your efforts. Currently the example is about cakes. These Shape, Size, Type array is not static. The all are comes fro DB. I event don't know what will come but when arrays
will come I want to take each and every possible combination.

According to your description, if these Shape, Size, Type array is not static. The all are comes from DB, I suggest that you could use cross join to know every possible combination.

Cross join A join whose result set includes one row for each possible pairing of rows from the two tables. For example, authors CROSS JOIN publishers yields a result set with one row for each possible author/publisher combination. The resulting SQL might
look like this:

Re: Create dynamic foreach loop for sequential search type in C#

(a) as the number of Shape, Size, Flavour, Image, and Message items increase in the database, the number of combinations also increase which means that more computed row results must be retrieved from the database.