初級 › The input string was not in a correct format の原因と直し方 › パターン5
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 '3,000' was not in a correct format.
at Program.Main(String[] args) in Program.cs:line 3
空欄を埋めてビルドを通す
桁区切りのカンマもint.Parseは数字として認識できません。
次の問題