0

I have an MVC application and I am stuck at a point where I need some help with the logic on how should I proceed.

I have a variable named URL where in I am putting URLs. These URLs contains parameters and they look as follows:-

http://example.com/{Parameter1}/{Parameter2}

Now {Parameter1} has 4 values a, b, c, d and {Parameter2} has 3 values 1, 2, 3.

Now using the values of these parameters I would get 12 URL combinations. I want to display all 12 combinations with the help of C#.

How can create the algorithm with the code to display the combinations?

Any advice would be appreciated.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user3328402
  • 47
  • 2
  • 3
  • 12

1 Answers1

1

That's fairly trivial using foreach loops for every parameter:

var parameters1 = new [] { "a", "b", "c", "d" };
var parameters2 = new [] { "1", "2", "3" };

foreach (var par1 in parameters1)
{
    foreach (var par2 in parameters2)
    {
        string url = string.Format("http://example.com/{0}/{1}", par1, par2);
        Console.WriteLine(url);
    }
}

You may want to put in a little recursion there if the parameter count varies.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272