Suppose we have a gear array
int[][] a = { new[] { 1, 2, 3, 4 }, new[] { 5, 6, 7, 8 }, new[] { 9, 10, 11, 12 } };
To get the sum of the second row and the sum of the second column, you can write both lines of code, respectively:
int rowSum = a[1].Sum(); int colSum = a.Select(row => row[1]).Sum();
But if we have a two-dimensional array definition
int[,] a = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
the above code will not work due to compiler errors:
Error 1 Wrong number of indices inside []; expected 2 Error 2 'int[*,*]' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'int[*,*]' could be found (are you missing a using directive or an assembly reference?)
So the question is: how to use LINQ methods with n-dimensional arrays, but not jagged? And where is the method for converting a rectangular array into a notched one?
PS I tried to find the answer in the documentation, but without result.