Task: Enter a two-dimensional integer ragged array and remove positive lines from it. Problem: at a certain point, the index pops out of the array. I can not understand how to fix it.
class Program { static int[][] MatrixInput(int n) { int m; int[][] arr = new int[n][]; for (int i = 0; i < n; i++) { Console.Write("Количество элементов в {0} строке: ", i + 1); m = int.Parse(Console.ReadLine()); arr[i] = new int[m]; } Console.Write("Введите элементы: \n"); for (int i = 0; i < n; ++i) for (int j = 0; j < arr[i].Length; ++j) { Console.Write("a[{0},{1}]= ", i, j); arr[i][j] = int.Parse(Console.ReadLine()); } return arr; } static void MatrixOutput(int[][] arr, int n) { for (int i = 0; i < n; i++) for (int j = 0; j < arr[i].Length; ++j) // Ошибка здесь Console.Write("{0,5} ", arr[i][j]); } static bool DeleteRow(int[] x) { foreach (int value in x) { if (value >= 0) { return false; } } return true; } static void Main(string[] args) { Console.WriteLine("Enter count of arrays"); int n = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the elements of matrix: "); int[][] array = MatrixInput(n); int[] x = new int[n]; int newSize = 0; foreach (int[] row in array) { if (DeleteRow(row)) { newSize++; } } int[][] output = new int[newSize][]; int rowCounter = 0; for (int i = 0; i < array.Length; i++) { if (DeleteRow(array[i])) { output[rowCounter] = array[i]; rowCounter++; } } Console.WriteLine("Matrix after removing: "); MatrixOutput(output, n); } } }