I have a piece of code working with an array of strings
// Complete the cavityMap function below. static string[] cavityMap(string[] grid) { var probablymax = 0; string symbolMax = "X"; var count_arr = grid.Length - 1; for (int i = 0; i <= count_arr; i++) { if (i != 0 && i != count_arr && int.Parse(grid[i]) > int.Parse(grid[0]) && int.Parse(grid[i]) > int.Parse(grid[count_arr])) { probablymax = i; var comparerer = int.Parse(grid[probablymax]); if (int.Parse(grid[i + 1]) < comparerer && int.Parse(grid[i - 1]) < comparerer) { probablymax = i ; **grid[probablymax] = symbolMax;** } } } return grid; } Where the line is highlighted - when run in the studio, the compiler missed, values are assigned. However, on the test site, the following error occurs, I quote:
nhandled Exception: System.FormatException: The input string was not in a correct format. at System.Number.StringToNumber (System.ReadOnlySpan
1[T] str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00045] in <04750267503a43e5929c1d1ba19daf3e>:0 at System.Number.ParseInt32 (System.ReadOnlySpan1 [T] s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x0000a] in <04750267503a43e5929c1d1ba19daf3e> 0 at System.I.A.It32.It32.a3e5929c1d1ba19daf3e> 0 at system.I.A.I.I.I.OncErnEnlySpan 1) s) [0x00016] in <04750267503a43e5929c1d1ba19daf3e>: 0 at Solution.cavityMap (System.String [] grid) [0x00071] in solution.cs: 33 at Solution.Main (System.String [] args) [0x00045] in solution. cs: 60 [ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: The input string is not correct. at System.Number.StringToNumber (System.ReadOnlySpan1[T] str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00045] in <04750267503a43e5929c1d1ba19daf3e>:0 at System.Number.ParseInt32 (System.ReadOnlySpan1 [T] s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x0000a] in <04750267503a43e5929c1d1ba19daf3e> 0 at System.I.A.It32.It32.a3e5929c1d1ba19daf3e> 0 at system.I.A.I.I.I.OncErnEnlySpan 1) s) [0x00016] in <04750267503a43e5929c1d1ba19daf3e>: 0 at Solution.cavityMap (System.String [] grid) [0x00071] in solution.cs: 33 at Solution.Main (System.String [] args) [0x00045] in solution. cs: 60
Please give ideas, thank you.
int.Parsecall. Specify the line on which the error occurs. Well, because There is an error in the format of the number, specify here the value that is passed toParse. - default localeSystem.Int32.Parse (System.String s) [0x00016] ... at Solution.cavityMap (System.String[] grid) [0x00071] in solution.cs:33This means that the error is thrown on line 33 solution.cs, whereInt32.Parseis called - default locale"X". Apparently, it needs to be processed in some special way, and not parsed. But the fact that the place of occurrence of an exception is determined incorrectly is in any case not good. - default locale