Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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#,我是C#的新手,我正在遵循TutorialPoint上发布的指南。我遵循他们的代码,但不完全是因为我不只是想复制和粘贴他们的代码,我想理解我正在编写的代码。所以他们的代码运行得很好,但是我的代码抛出了标题中显示的错误,我不知道为什么。我不知道我的代码是如何工作的,但他们的代码是。这是我的密码: using System; namespace Learning { class Rectangle { double length; double wi

我是C#的新手,我正在遵循TutorialPoint上发布的指南。我遵循他们的代码,但不完全是因为我不只是想复制和粘贴他们的代码,我想理解我正在编写的代码。所以他们的代码运行得很好,但是我的代码抛出了标题中显示的错误,我不知道为什么。我不知道我的代码是如何工作的,但他们的代码是。这是我的密码:

using System;

namespace Learning
{
    class Rectangle
    {
        double length;
        double width;

        public void setDimensions()
        {
            length = 4.5;
            width = 3.5;
        }

        public double getArea()
        {
            return length * width;
        }

        public void displayInfo()
        {
            Console.WriteLine("Length: {0)", length);
            Console.WriteLine("Width: {0}", width);
            Console.WriteLine("Area: {0}", getArea());
        }
    }

    class ExecRect
    {
        static void Main(string[] args)
        {
            Rectangle r = new Rectangle();
            r.setDimensions();
            r.displayInfo();
        }
    }
}
以下是他们的代码:

using System;

namespace RectangleApplication {
   class Rectangle {
      
      // member variables
      double length;
      double width;
      
      public void Acceptdetails() {
         length = 4.5;    
         width = 3.5;
      }
      public double GetArea() {
         return length * width; 
      }
      public void Display() {
         Console.WriteLine("Length: {0}", length);
         Console.WriteLine("Width: {0}", width);
         Console.WriteLine("Area: {0}", GetArea());
      }
   }
   class ExecuteRectangle {
      static void Main(string[] args) {
         Rectangle r = new Rectangle();
         r.Acceptdetails();
         r.Display();
         Console.ReadLine(); 
      }
   }
}
我哪里出错了


编辑:哈哈,大错特错了。在第23行,用a)而不是}关闭花括号。谢谢

您忘记了在方法
displayInfo
中使用
“Length:{0)”,Length
关闭大括号


我建议您在
Console.WriteLine($“Length:{Length}”)

引发异常的是哪一行?这对于了解问题的根源非常有用。在
Console.WriteLine(“Length:{0”)的字符串中,在
0
之后缺少一个右括号,length);
您有一个括号。请注意,
Console.WriteLine($“length:{length}”)
不允许出现相同的错误,因为插值字符串是在编译时检查的。