In this post, the Linq to XML query result are accessed with iterator as follows.
foreach (var elem in elems) {
var res = elem.Elements("ClassKeyName");
foreach (var e in res) {
Console.WriteLine(e.Value);
}
}
Can I access the result with []? For example, I want to use as follows,
foreach (var elem in elems) {
var res = elem.Elements("ClassKeyName");
Console.WriteLine(res[0].Value);
}
However, I got this error message
xmlparse.cs(18,34): error CS0021:
Cannot apply indexing with [] to an expression of type
`System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>'