using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<List<int>> nestedList = new List<List<int>> {
new List<int> { 1, 2, 3 },
new List<int> { 4, 5, 6 },
new List<int> { 7, 8, 9 }
};
// Convert the nested list to a 2D array
int[,] array = ConvertNestedListToArray(nestedList);
for (int i = 0; i < array.GetLength(0); i++) {
for (int j = 0; j < array.GetLength(1); j++) {
Console.Write(array[i, j] + " ");
}
Console.WriteLine();
}
}
static int[,] ConvertNestedListToArray(List<List<int>> nestedList) {
// Get the number of rows and columns
int rows = nestedList.Count;
int cols = nestedList[0].Count;
// Initialize the 2D array
int[,] array = new int[rows, cols];
// Populate the array with values from the nested list
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
array[i, j] = nestedList[i][j];
}
}
return array;
}
}
/*
run:
1 2 3
4 5 6
7 8 9
*/