C# variable contents altered when using a debugger
In my C# program, I parse an XML file, which has been created before with
XSLT. When I normally run the program, variable extraClasses contains 3
nodes. The problem is that the selector I am using must return 2 nodes
when applied to this specific XML.
Trying to find the bug in my code, I used a debugger. When I examined the
value of variable extraClasses, the node count was 2, and the result was
the expected. When the variable is not examined, node count is 3 and the
results are wrong.
Furthermore, when I add an if statement to check if the extraClasses count
is more than 2, after the assignment, my program works fine
(extraClasses.Count = 2).
Why is this happening? Why the value examination alters the contents of
the variable? I am using C# and .NET Framework 4.
var extraClasses = xml.SelectNodes("//Class[@level='2']");
foreach (XmlElement extraClass in extraClasses) {
/* create some new nodes and append to the xml */
}
No comments:
Post a Comment