Attribute combinations of a typical product under apparels category

Print all the attribute combinations of a typical product under apparels category

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[][] jaggedArray = {
                                 new string[]{ "Red", "Blue", "Green" },
                                 new string[]{ "XL", "X", "M", "S" },
                                 new string[]{ "Checks" , "Lines" },
                               };
            for (int i = 0; i < jaggedArray.Length; i++)
            {
                for (int j = 0; j < jaggedArray[i].Length; j++)
                {
                    Console.Write(jaggedArray[i][j] + " ");
                }
                System.Console.WriteLine();
            }
            System.Console.WriteLine("==================");
            Combination(jaggedArray, 0, "");
        }
        public static void Combination(string[][] jaggedArray, int depth, string str)
        {
            if (depth == jaggedArray.Length)
            {
                Console.WriteLine(str);
                return;
            }
            if (depth < jaggedArray.Length)
            {
                for (int i = 0; i < jaggedArray[depth].Length; i++)
                {
                    if (depth == jaggedArray.Length - 1)
                    {
                        Combination(jaggedArray, depth + 1, str + jaggedArray[depth][i] + "");
                    }
                    else
                    {
                        Combination(jaggedArray, depth + 1, str + jaggedArray[depth][i] + "-->");
                    }
                }
            }
        }
    }
}

Output
=======
Red Blue Green
XL X M S
Checks Lines
==================
Red-->XL-->Checks
Red-->XL-->Lines
Red-->X-->Checks
Red-->X-->Lines
Red-->M-->Checks
Red-->M-->Lines
Red-->S-->Checks
Red-->S-->Lines
Blue-->XL-->Checks
Blue-->XL-->Lines
Blue-->X-->Checks
Blue-->X-->Lines
Blue-->M-->Checks
Blue-->M-->Lines
Blue-->S-->Checks
Blue-->S-->Lines
Green-->XL-->Checks
Green-->XL-->Lines
Green-->X-->Checks
Green-->X-->Lines
Green-->M-->Checks
Green-->M-->Lines
Green-->S-->Checks
Green-->S-->Lines
Press any key to continue . . .
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s