As BoltClock notes, XmlNodeList implements only IEnumerable .
The foreach automatically casts for you off-screen, so this:
List<object> values = new List<object> { "x", "y", "z" }; foreach (string x in values) { ... }
is completely legal and performs a throw (which may, of course, throw an exception) for each value.
It's not entirely clear to me what you mean by your second question, but I just recommend that you explicitly use the XmlNode in your loop. If you really want to use var , you can write:
foreach (var foo in xmlNodeList.Cast<XmlNode>())
but for me it seems superfluous ...
Jon skeet
source share