给出这段代码:
// Get first key //
int? keyEDISecurity = this.WorkQueue.GetNextWorkItem();
// Done? //
while (keyEDISecurity != null)
{
try
{
...
// Write changes //
List<ISNLEditableObject> changedRows = this.WorkQueue.GetChangedRows((int)keyEDISecurity);
this.Writer.Write(changedRows, WriteFlags.Transactional);
...
}
catch (Exception ex)
{
// Exception handling/logging code
}
finally
{
// Remove all data for the KeyEDISecurity from work queue cache //
this.WorkQueue.RemoveData((int)keyEDISecurity);
}
// Get next work item //
keyEDISecurity = this.WorkQueue.GetNextWorkItem();
}
Run Code Online (Sandbox Code Playgroud)
在具有声明List changedRows的行之前,changedRows应为null.然后它会超出范围,因为你得到了下一个工作项.然后你回来,在同一行之前,如果你访问changedRows,它应该再次为null,因为它没有被声明.
如果您中断并编辑,那么,正如您所期望的那样,您无法访问changedRows,因为它已超出范围,尚未声明.如果您评估它(通过鼠标悬停或使用立即窗口),您可以访问上一次循环迭代中的changedRows.WTH?
谁见过这个?它不会影响程序,因为它似乎在代码中正常运行,但调试器问题导致浪费时间,因为它没有按预期运行.我想知道这是否是预期的行为,所以我可以在将来知道,而不是浪费时间.