日期:2014-05-18  浏览次数:21207 次

请大家帮我看一下这个程序哪里出了问题,感激不尽!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace p4_1
{
  class Program
  {
  static void Main(string[] args)
  {
  double x1 = 1.0 / 0;
  double x2 = -1.0 / 0;
  double x3 = 0.0 / 0;
  Console.Write("1.0/0={0};",x1);
  Console.Write("-1.0/0={0};",x2);
  Console.WriteLine("0.0/0={0};", x3);
  BasicCompute(0, x1);
  BasicCompute(0, x2);
  BasicCompute(0, x3);
  BasicCompute(x1, x1);
  BasicCompute(x1, x2);
  }
  static void BasicCompute(double x1,double x2)
  {
  Console.Write("{0}+{1|={2};", x1, x2, x1 + x2);
  Console.WriteLine("{0}-{1}={2};", x1, x2, x1-x2);
  Console.Write("{0}*{1}={2};", x1, x2, x1 * x2);
  Console.WriteLine("{0}/{1}={2}\n", x1, x2, x1 / x2);


  }
  }
}

“System.FormatException”类型的未经处理的异常出现在 mscorlib.dll 中。

其他信息: 输入字符串的格式不正确。


这个是什么情况啊?我的代码跟书上一样,就出了个这问题,请大神们指教!



------解决方案--------------------
C# code

      static void BasicCompute(double x1, double x2)
      {
          Console.Write("{0}+{1}|={2};", new object[]{ x1, x2, x1 + x2});
          Console.WriteLine("{0}-{1}={2};", new object[]{x1, x2, x1 - x2});
          Console.Write("{0}*{1}={2};", new object[]{x1, x2, x1 * x2});
          Console.WriteLine("{0}/{1}={2}\n", new object[]{x1, x2, x1 / x2});


      }