Jor*_*rdy 8 c# debugging visual-studio
当我看到奇怪的东西时,我正在调试我的代码.基本上它归结为:

你在这里看到的是一个带有负值的unsigned int ...
我还注意到一些周围的变量没有value pop-up(?)而其他变量没有.但是这个变量是唯一一个具有不可能价值的变量.
这怎么可能?
我只有C#Visual Studio 2010,所以我不知道其他版本或不同语言存在此问题.如果是这种情况,我会相应地更改标题和标签.
在调试时,Visual Studio将跟踪当前上下文中的每个变量.
考虑以下代码:
void SomeMethod1()
{
int j = 0;
}
void SomeMethod2()
{
int i = 0;
}//Breakpoint on this line.
Run Code Online (Sandbox Code Playgroud)
当程序中断时,当前上下文是SomeMethod2.此时,开发人员无法检查其价值j.这是因为int j 当前上下文中不是变量.
OP描述行为背后的实际原因:
如果在Visual Studio检查名称的变量在目前情况下存在,不检查,如果变量本身在目前情况下存在.
因此,如果我们将变量的名称更改j为iin SomeMethod1,我们可以突然查看其"值".想象一下如果iin SomeMethod2是一个字符串会有多奇怪:

你什么时候该知道的?
每当你有一段代码时,它不能立即清楚当前的上下文是什么.我在下面的代码中遇到了这个问题:
private double CalculateFast(double d)
{
//Depending on the size of d, either [Method 1] or [Method 2] is faster.
//Run them both and use the answer of the first method to finish.
Tasks.Task.Factory.StartNew(() = >
{
//Method 1
}
//Method 2
return answer;
}
Run Code Online (Sandbox Code Playgroud)
我正在调试,Method 2但我想我也可以查看变量Method 1.但事实并非如此,因为Method 1它有自己的背景.
| 归档时间: |
|
| 查看次数: |
2673 次 |
| 最近记录: |