迭代器模式传递参数

时间:2012-08-06 19:45:35

标签: c# design-patterns

如何通过参数传递一个我Iterator的变量?

protected void LeXMLNode(FileUpload fupArquivo)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(fupArquivo.FileContent);

            XmlNodeList ndo = doc.SelectNodes("*");

            var it = ndo.GetEnumerator();
            using (it as IDisposable)
            while (it.MoveNext())
            {                
                //// Pass the variable it as parameter
            }
        }

1 个答案:

答案 0 :(得分:1)

使用.Current属性:

using (var it = ndo.GetEnumerator())
    while (it.MoveNext())
    {                
        //// Pass the variable it as parameter
        SomeFunction(it.Current);
    }