如何Visual Studio的调试过程中显示System.Double? [英] How does Visual Studio display a System.Double during debugging?
问题描述
尝试调试下面的简单程序,鼠标放在 X
中的每一个步骤(或添加监视为 X
或其他)
Try debugging the following simple program, and mouse over x
in each step (or "Add Watch" for x
or whatever).
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
。它调用哪个方法用于此目的?有没有一种方法可以让我得到了同样的字符串表示编程?
So, apparently VS has its own way to display a System.Double
. Which method does it call for this purpose? Is there a way I can get the very same string representation programmatically?
(试过这一点与Visual Studio 2010专业版。)
(Tried this out with Visual Studio 2010 Professional.)
推荐答案
目前其核心都C#和VB.Net EE的使用 _ecvt_s
函数用于格式化双
成一个字符串。
At their core both the C# and VB.Net EE's use the _ecvt_s
function for formatting a double
into a string.
- http://msdn.microsoft.com/en-us/library/ehz2dset(v=vs.80).aspx
无论做的结果字符串清理一点点,使显示更加C#和VB一样,处理一些角落情况有点更好。无论是 _ecvt_s
函数或清理代码可以负责你看到的差异。很难说一目了然
Both do a little bit of cleanup on the resulting string to make the display more C# and VB like and handle some corner cases a bit nicer. Either the _ecvt_s
function or the cleanup code could be responsible for the differences you see. Hard to tell at a glance
也许有人会问,为什么我们会经历这一切麻烦而不是说只叫的ToString $ C $的C>的值并显示。有几个原因,我们不这样做。
Some may ask why we would go through all of this trouble instead of saying just calling ToString
on the value and displaying that. There are a couple of reasons we don't do this.
第一个是简单的功能评价,甚至的ToString
,是最昂贵的行动EE可以进行。常见的场景真正型材表明我们的时间超过98%用于做功能评价。任何时候,我们就可以避免一个函数计算,我们因为对性能的影响做。
The first is simply that function evaluation, even ToString
, is the single most expensive action the EE can undertake. Profiles of common real scenarios show that over 98% of our time was spent doing function evaluation. Any time we can avoid a func eval we do because of the performance implications.
第二个原因很简单,功能评价并不总是可用。有一些情况下,如果函数计算是不可用的,但人们仍然期望看到像双击
, INT $ C $为基本类型的显示器C>等......以他们离开将基本上杀调试经验。因此,我们必须在不
的ToString
支持来解决这个问题。
The second reason is simply that function evaluation isn't always available. There are a number of cases where func eval is unavailable yet people still expect to see a display for primitive types like double
, int
, etc ... Taking them away would essentially kill the debugging experience. Hence we need to solve this problem without ToString
support.
这篇关于如何Visual Studio的调试过程中显示System.Double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!