Behavior of LoadXml and SelectNodes
<p>I have code similar to the first below</p>

<pre><code>String xml1 =
    @"&lt;resultset&gt;
        &lt;result&gt;
            &lt;alamakota /&gt;
        &lt;/result&gt;
    &lt;/resultset&gt;";
String xml2 =
    @"&lt;resultset/&gt;";
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xml1);
XmlNodeList nodes1 = xDoc.SelectNodes("/resultset/result");
xDoc.LoadXml(xml2);
XmlNodeList nodes2 = xDoc.SelectNodes("/resultset/result");
Console.WriteLine(nodes1.Count);
Console.WriteLine(nodes2.Count);
</code></pre>

<p>I would expect that WriteLine methods gives 1 and 0 but not always. In normal program run it will give double 0. Also during debug when I put breakpoint on second SelectNodes and check value of nodes1.Count in VS it gives me 1 and 0 at the end. It seems that SelectNodes is evaluated during first check of XmlNodeList and not in line where it is in code, for example code below will give 1 and 0 every time it runs</p>

<pre><code>String xml1 =
    @"&lt;resultset&gt;
        &lt;result&gt;
            &lt;alamakota /&gt;
        &lt;/result&gt;
    &lt;/resultset&gt;";
String xml2 =
    @"&lt;resultset/&gt;";
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xml1);
XmlNodeList nodes1 = xDoc.SelectNodes("/resultset/result");
Int32 c1 = nodes1.Count;
xDoc.LoadXml(xml2);
XmlNodeList nodes2 = xDoc.SelectNodes("/resultset/result");
Console.WriteLine(nodes1.Count);
Console.WriteLine(nodes2.Count);
</code></pre>

<p>I know that I can do xDoc = new XmlDocument() after first SelectNodes and it will work like expected but I wonder if this is how it should work because I can't find this scenario at msdn. If yes then why? Please point me to some documentation.</p>