I have two arrays of always equal size, and I want to find all possible combination sets of these two arrays.
For example:
var names = new [] { "John", "Alex", "Peter", "Eric" };
var letters = new [] { "A", "B", "C", "D" };
I would like the result to be returned as a List of Dictionary:
var combinationSets = new List<Dictionary<string, string>>
{
new Dictionary<string, string>
{ {"John", "A"},
{"Alex", "B"},
{"Peter", "C"},
{"Eric", "D"}},
new Dictionary<string, string>
{ {"John", "B"},
{"Alex", "C"},
{"Peter", "D"},
{"Eric", "A"}},
...
};
Edit: None of the values in the two arrays can repeat itself in the dictionaries, like:
new Dictionary<string, string>
{ {"John", "A"},
{"Alex", "A"},
{"Peter", "C"},
{"Eric", "D"}}
Any tips on how to solve this?
Edit: I don't think cartesian product can be used since it will return
var cartesianProduct= new []
{
new []{ "John", "A" },
new []{ "Alex", "B" },
new []{ "Peter", "C" },
new []{ "John", "D" },
new []{ "John", "B" },
new []{ "Alex", "C" },
new []{ "Peter", "D" },
new []{ "John", "A" },
...
}