Array operations with n-dimensional array using LINQ (C#)

后端 未结 6 1399
温柔的废话
温柔的废话 2021-02-06 03:23

Assume we have a jagged array

int[][] a = { new[] { 1, 2, 3, 4 }, new[] { 5, 6, 7, 8 }, new[] { 9, 10, 11, 12 } };

To get a sum of second row a

6条回答
  •  后悔当初
    2021-02-06 03:42

    About your question "How to use LINQ methods with n-dimensional arrays":

    You can't use most LINQ methods with a n dimensional array, because such an array only implements IEnumerable but not IEnumerable and most of the LINQ extension methods are extension methods for IEnumerable.

    About the other question: See dtb's answer.

提交回复
热议问题