初級 › The input string was not in a correct format の原因と直し方 › パターン3
The input string was not in a correct format の原因と直し方
int.Parseなどの変換メソッドに、数値として解釈できない文字列を渡したときに発生します。
1 class Program { 2 static void Main(string[] args) { 3 int n = int.Parse(____); ^ 4 System.Console.WriteLine(n); 5 } 6 }
Unhandled exception. System.FormatException: The input string '' was not in a correct format.
at Program.Main(String[] args) in Program.cs:line 3
空欄を埋めてビルドを通す
空文字列は数字を1つも含まないため、int.ParseはFormatExceptionを投げます。
次の問題