This example defines extension methods in the static ArrangingExtensions class. The following code shows the main Permutations method:
// Find permutations containing the desired number of items.public static List<List<T>> Permutations<T>(this T[] values, int numPerGroup){ int numValues = values.Count(); bool[] used = new bool[numValues]; List<T> currentSolution = new List<T>(); return FindPermutations(values, numPerGroup, currentSolution, used, numValues);}
This method gets the number of values in the array and then creates an array of bool with the same size. The program will use that array to keep track of which values are in the solution as the code works on it.
The code then creates a List<T> to hold the current solution. ...