Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.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.Format异常。输入的格式不正确)_C#_Error Handling - Fatal编程技术网

C# (错误:已引发System.Format异常。输入的格式不正确)

C# (错误:已引发System.Format异常。输入的格式不正确),c#,error-handling,C#,Error Handling,应用程序正在运行,我在程序中有两个类,但我的第二个类不断出现此错误 class SandwichBuild { private string sandwichname; private double ingred1, ingred2, ingred3, ingred4; public SandwichBuild(string input1, string input2, string input3, string input4, string input5) //

应用程序正在运行,我在程序中有两个类,但我的第二个类不断出现此错误

class SandwichBuild 
{
    private string sandwichname;
    private double ingred1, ingred2, ingred3, ingred4;

    public SandwichBuild(string input1, string input2, string input3, string input4, string input5)   //sets variables
    {
        sandwichname = input1;
        ingred1 = double.Parse(input2);
        ingred2 = double.Parse(input3);
        ingred3 = double.Parse(input4);
        ingred4 = double.Parse(input5);
    }

    public void PrintOutput()
    {
        WriteLine(sandwichname + " " + ingred1 + " " + ingred2 + " " + ingred3 + " " + ingred4);  //Output for users responses
    }
}

我需要我的应用程序显示最终响应

,如果将非
double
的字符串传递给
double.Parse(…)
,则会引发异常

此代码将引发该异常

 var result = double.Parse("Not a double or even a number.");

因此,您正在将无效字符串传递到构造函数中。

在哪一行收到错误?我在第7行收到错误。ingred1=double.Parse(input2);您在
input2
中传递的是什么?传递给类构造函数的是什么?什么是
WriteLine()