简体   繁体   English

“ mscorlib.dll中发生了'System.FormatException'类型的未处理的异常”

[英]“An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll”

    static void Main(string[] args)
    {
        int numVal = -1;
        int numval = -1;
        bool repeat = true;

        Console.WriteLine("Welcome to the perpendicular line finder!");

        while (repeat == true)
        {
            Console.WriteLine("Please write the gradient of the line");


            string userValue = Console.ReadLine();

            try
            {
                numVal = Convert.ToInt32(userValue);
            }
            catch (FormatException e)
            {
                Console.WriteLine("That is not a valid number");
                continue;
            }
            catch (OverflowException e)
            {
                Console.WriteLine("That number is too large, sorry i cannot help you");
                continue;
            }
            Console.WriteLine("So the gradient is {0}? Y/N", numVal);
            string go = Console.ReadLine();
            if (go == "Y" || go == "y")
            {
                repeat = true;
            }
            else
            {
                repeat = false;
            }

            Console.WriteLine("Please write the number that was added or subtracted");
            Console.WriteLine("but if it was subtracted leave the minus sign in");

            string userValue2 = Console.ReadLine();

            try
            {
                numval = Convert.ToInt32(userValue2);
            }
            catch (FormatException e)
            {
                Console.WriteLine("That is not a valid number");
                continue;
            }
            catch (OverflowException e)
            {
                Console.WriteLine("That number is too large, sorry i cannot help you");
                continue;
            }
            Console.WriteLine("So the added or subtracted number is {0}? Y/N", numval);
            string go1 = Console.ReadLine();
            if (go1 == "Y" || go1 == "y")
            {
                repeat = true;
            }
            else
            {
                repeat = false;
            }

            int answer = -1 / numVal; 

            Console.WriteLine("A perpendicular line to y = {0}x+{1} is y = {3}x", numVal, userValue2, answer);   
            Console.ReadLine();
        }

It comes up with this error: An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll This happens when I run the code and get down to the second to last line of code. 出现此错误:mscorlib.dll中发生了类型为'System.FormatException'的未处理异常。当我运行代码并转到第二行到最后一行时,会发生这种情况。 I am new to c# and have no idea of what to do please help me. 我是C#的新手,不知道该怎么做,请帮助我。

Console.WriteLine("A perpendicular line to y = {0}x+{1} is y = {3}x",
    numVal, userValue2, answer);   

The format string refers to a non-existent argument {3} , replace with {2} . 格式字符串引用了不存在的参数{3} ,替换为{2}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mscorlib.dll中发生了'System.FormatException'类型的未处理异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生了未处理的“System.FormatException”类型异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生了'System.FormatException'类型的未处理的异常其他信息:输入字符串的格式不正确 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format 尝试解析DateTime时-mscorlib.dll中发生了'System.FormatException'类型的未处理异常 - When trying to parse DateTime - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll 在C#中将十进制转换为十六进制,并出现错误“ mscorlib.dll中发生了'System.FormatException'类型的未处理异常” - decimal to hexadecimal in c# with mistake “An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll” mscorlib.dll中发生“ System.FormatException”类型的未处理异常,被卡住 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll, stuck mscorlib.dll 中发生了类型为“System.FormatException”的未处理异常 谁能帮我解决这个错误? - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Can anyone help me with this error? c# 中的运行时错误 - mscorlib.dll 中发生类型为“System.FormatException”的未处理异常 - Run-time error in c# - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生类型'System.FormatException'的异常,但未在用户代码中处理 - An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in the user code mscorlib.dll 中出现“System.FormatException”类型的异常,但未在用户代码中处理 - An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM