With vs without using LINQ query operators when enumerating elements from XML with no filtering



In the MSDN documentation for the XElement.Elements(XName) method, there is the following example:



XElement xmlTree = new XElement("Root",
new XElement("Type1", 1),
new XElement("Type1", 2),
new XElement("Type2", 3),
new XElement("Type2", 4),
new XElement("Type2", 5)
);

IEnumerable<XElement> elements =
from el in xmlTree.Elements("Type2")
select el;
foreach (XElement el in elements)
Console.WriteLine(el);


Is there a difference between that and the following, which produces the same result?



foreach (XElement el in xmlTree.Elements("Type2"))
Console.WriteLine(el);


Is there a reason the query operators were used here?


No comments:

Post a Comment