【发布时间】:2012-03-25 20:38:03
【问题描述】:
在 VS2010 SP1 中调试迭代器方法(使用 DEBUG 设置...没有编译器优化),我的变量之一,操作数,根据 Quick Watch 中的“在当前上下文中不存在”立即窗口(如果我将鼠标悬停在变量上,我也不会弹出窗口)。
变量在作用域内。
对可能导致 tis 的原因或如何避免它的想法?
private IEnumerable<Answer> CreateVirtualFormulaAnswers(Question question, List<Answer> answers)
{
string[] formulaParts = question.Formula.Split(FORMULA_SPLIT, StringSplitOptions.None);
string formula = formulaParts[0].Trim();
if (formulaParts.Length != 2) throw new Exception("Formula format is incorrect: " + question.Formula);
// At this point:
// formulaParts.Length = 2
// formulaParts has a non-null string at each index
// Mouse over of "op" in VS2010 debugger does not show any popup
// Quick watch and immediate window both state: "The name 'operand' does not exist in the current context"
string operand = formulaParts[1].Trim();
string answerText = (from a in answers where a.QuestionCode == op select a.Text).SingleOrDefault();
if (answerText != null)
{
yield return new Answer()
{
/* Initialization code here based on formula */
};
}
}
【问题讨论】:
-
当您移动到下一条指令时,它是否显示为在范围内? AFAIK 您必须通过声明才能将其显示为“范围内”。
-
@Tudor:是的,通过声明后问题依旧。
-
嗯,我可以在我自己的 VS 2010 中重现该问题。它必须是一个“功能”。 :)
-
@Tudor:我想你是对的。我添加了其他发现作为答案。希望它能帮助其他人避免挠头。
标签: visual-studio-2010 debugging