Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 已引发System.FormatException_C# - Fatal编程技术网

C# 已引发System.FormatException

C# 已引发System.FormatException,c#,C#,我正在尝试转换我的整数并继续获取System.FormatException已引发。我似乎不明白为什么,这让我发疯。我正在用c语言编程# 使用系统; 名称空间Bank_数据库 { 类主类 { 公共静态void Main(字符串[]args) { //弦; //Ints; int x=24; int y=12; int Correct=0; //装载; 对于(int a=0;a您可以使用int.TryParse来避免异常 替换 int Answer = Convert.ToInt32(Consol

我正在尝试转换我的整数并继续获取System.FormatException已引发。我似乎不明白为什么,这让我发疯。我正在用c语言编程#

使用系统;
名称空间Bank_数据库
{
类主类
{
公共静态void Main(字符串[]args)
{
//弦;
//Ints;
int x=24;
int y=12;
int Correct=0;
//装载;

对于(int a=0;a您可以使用
int.TryParse
来避免异常

替换

int Answer = Convert.ToInt32(Console.ReadLine());

int Answer = Convert.ToInt32(Console.ReadLine());
int Answer;
if (!int.TryParse(Console.ReadLine(), out Answer))
{
    Console.WriteLine("Invalid Number");
}