Returns an IEnumerator object to iterate through the selected node set.
An IEnumerator object to iterate through the selected node set.
The enumerator is positioned on the current position of the System.Xml.XPath.XPathNodeIterator object.
There are two ways to iterate over an System.Xml.XPath.XPathNavigator collection by using the System.Xml.XPath.XPathNodeIterator class.
One way is to use the XPathNodeIterator.MoveNext method and then call XPathNodeIterator.Current to get the current System.Xml.XPath.XPathNavigator instance, as in the following example:
code reference: XPathNavigatorMethods#55
Another way is to use a foreach loop to call the XPathNodeIterator.GetEnumerator method and use the returned IEnumerator interface to enumerate the nodes, as in the following example:
code reference: XPathNavigatorMethods#56
You should either use the XPathNodeIterator.MoveNext method and XPathNodeIterator.Current or use the XPathNodeIterator.GetEnumerator method. Combining these two approaches can cause unexpected results. For example, if the XPathNodeIterator.MoveNext method is called first, and then the XPathNodeIterator.GetEnumerator method is called in the foreach loop, the foreach loop will not start enumerating the results from the beginning of the collection, but from the position after the XPathNodeIterator.Current method.