尝试调试以下简单程序,并x
在每个步骤中将鼠标悬停(或“添加监视”x
或其他)。
using System;
using System.Globalization;
static class Program
{
static double x;
static void Main()
{
x = 2d;
// now debugger shows "2.0", as if it has used
// x.ToString("F1", CultureInfo.InvariantCulture)
x = 8.0 / 7.0;
// now debugger shows "1.1428571428571428", as if it had used
// x.ToString("R", CultureInfo.InvariantCulture)
// Note that 17 significant figures are shown, not the usual 15.
x = -1e-200 / 1e200;
// now debugger shows "0.0"; there is no indication that this is really negative zero
//
Console.WriteLine(1.0 / x); // this is negative infinity
}
}
因此,显然 VS 有自己的方式来显示System.Double
. 它为此目的调用了哪种方法?有没有办法以编程方式获得完全相同的字符串表示?
(使用 Visual Studio 2010 Professional 进行了尝试。)