初級 › The input string was not in a correct format の原因と直し方 › パターン2
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 '12.5' was not in a correct format.
at Program.Main(String[] args) in Program.cs:line 3
空欄を埋めてビルドを通す
int.Parseは小数点を含む文字列を受け付けません。小数はdouble.Parseを使う必要があります。
次の問題