根据标题,我需要在 C#/.NET 4 中创建一个方法,该方法可以打乱 XPathNodeIterator 对象的顺序。该方法需要遍历所有子项 ("/*") 以随机重新排序子项。
我需要一些帮助才能开始 - 我所拥有的只是方法 stub :
public XPathNodeIterator RandomizeXPathNodeIterator(XPathNodeIterator iterator)
感谢任何帮助! 谢谢
最佳答案
您可以将 XPathNodeIterator 迭代为:
XPathNavigator[] positions = new XPathNavigator[iterator.Count];
int i = 0;
while (iterator.MoveNext())
{
XPathNavigator n = iterator.Current;
positions[i] = n;
i++;
}
然后,打乱数组
关于c# - 我如何遍历 XPathNodeIterator 并随机化它的 child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13010657/