Please help, now I have a matrix, I want use Combination algorithm to generate a array for length 6
The first thanks a lot for your help , the following is my matrix, I want to implement combination algorithm between multiple arrays in LINQ for this matrix.
int[,] cj = {
{ 10, 23, 16, 20 },
{ 22, 13, 1, 33 },
{ 7, 19, 31, 12 },
{ 30, 14, 21, 4 },
{ 2, 29, 32, 6 },
{ 18, 26, 17, 8 },
{ 25, 11, 5, 28 },
{ 24, 3, 15, 27 }
};
other:
public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<T> elements, int k)
{
return k == 0 ? new[] { new T[0] } :
ele开发者_StackOverflow中文版ments.SelectMany((e, i) =>
elements.Skip(i + 1).**Combinations**(k - 1).Select(c => (new[] { e }).Concat(c)));
}
The above method has a error in my project, System.Collections.Generic.IEnumerable' does not contain a definition for 'Combinations' and no extension method 'Combinations' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?
I use .Net Framework3.5, what is the reason it?
The error you have is actually a compiler error and should be claimed at the line you try invoking your extension method. Have you made sure you extension method is declared in a static class and it's namespace has been imported?
I see you are recursively invoking your extension method, but I can compile your code just fine. The error should be at another callsite.
精彩评论