XPathNodeIterator.GetEnumerator Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns an IEnumerator object to iterate through the selected node set.
public:
virtual System::Collections::IEnumerator ^ GetEnumerator();
public virtual System.Collections.IEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Overridable Function GetEnumerator () As IEnumerator
Returns
An IEnumerator object to iterate through the selected node set.
Implements
Remarks
The enumerator is positioned on the current position of the XPathNodeIterator object.
There are two ways to iterate over an XPathNavigator collection by using the XPathNodeIterator class.
One way is to use the MoveNext method and then call Current to get the current XPathNavigator instance, as in the following example:
while (nodeIterator->MoveNext())
{
XPathNavigator^ n = nodeIterator->Current;
Console::WriteLine(n->LocalName);
}
while (nodeIterator.MoveNext())
{
XPathNavigator n = nodeIterator.Current;
Console.WriteLine(n.LocalName);
}
While nodeIterator.MoveNext()
Dim n As XPathNavigator = nodeIterator.Current
Console.WriteLine(n.LocalName)
End While
Another way is to use a foreach
loop to call the GetEnumerator method and use the returned IEnumerator interface to enumerate the nodes, as in the following example:
for each (XPathNavigator^ n in nodeIterator)
Console::WriteLine(n->LocalName);
foreach (XPathNavigator n in nodeIterator)
Console.WriteLine(n.LocalName);
For Each n As XPathNavigator In nodeIterator
Console.WriteLine(nav.LocalName)
Next
You should either use the MoveNext method and Current or use the GetEnumerator method. Combining these two approaches can cause unexpected results. For example, if the MoveNext method is called first, and then the 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 Current method.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기