Я хотел сделать это в одну строку... Но не смог ;(
string.Join(",", a.Select(z => z.Cast<List<int[]>>().Select(x => x.Select(c => c))).ToList());
Поэтому вот развёрнутый рабочий вариант:
int[][,] a = new int[3][,]
{
new int [,] { {3,1}, {4,2} },
new int [,] { {7,3},{8,11} },
new int [,] { {17,12} ,{21,73} },
};
StringBuilder sb = new StringBuilder("Array:");
for (int q = 0; q < a.Length; q += 1)
{
sb.Append("\n");
for (int w = 0; w < a[q].GetLength(0); w += 1)
{
for (int e = 0; e < a[q].GetLength(1); e += 1)
sb.Append(a[q][w,e] + " ");
sb.Append("\n");
}
}
Вывод:
Array:
3 1
4 2
7 3
8 11
17 12
21 73
Вы так же можете поиграть с вариациями, как пример, получить на выводе:
int[][,] a = new int[3][,]
{
new int [,] { {3, 1}, {4, 2} },
new int [,] { {7, 3}, {8, 11} },
new int [,] { {17, 12}, {21, 73} },
}
С помощью:
int[][,] a = new int[3][,]
{
new int [,] { {3,1}, {4,2} },
new int [,] { {7,3},{8,11} },
new int [,] { {17,12} ,{21,73} }
};
StringBuilder sb = new StringBuilder($"int[][,] a = new int[{a.Length}][,]\n" + "{");
for (int q = 0; q < a.Length; q += 1)
{
sb.Append("\n new int [,] { ");
for (int w = 0; w < a[q].GetLength(0); w += 1)
{
sb.Append("{");
for (int e = 0; e < a[q].GetLength(1); e += 1)
{
sb.Append(a[q][w, e]);
if (e + 1 != a[q].GetLength(1))
sb.Append(", ");
}
sb.Append("}");
if (w + 1 != a[q].GetLength(0))
sb.Append(",");
sb.Append(" ");
}
sb.Append("},");
}
sb.Append("\n}");
Console.WriteLine(sb);
Console.WriteLine();
.array2d[0].GetLength(0)
заменить наarray2d[i].GetLength(0)
, тоже самое, очевидно, и для.GetLength(1)