I have an ArrayList[] myList and I am trying to create a list of all the permutations of the values in the arrays.
EXAMPLE: (all values are strings)
Here is a version which uses very little code, and is entirely declarative
public static IEnumerable> GetPermutations(IEnumerable collection) where T : IComparable
{
if (!collection.Any())
{
return new List>() {Enumerable.Empty() };
}
var sequence = collection.OrderBy(s => s).ToArray();
return sequence.SelectMany(s => GetPermutations(sequence.Where(s2 => !s2.Equals(s))).Select(sq => (new T[] {s}).Concat(sq)));
}