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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.