I have came across both these keywords in the VS IntelliSense. I tried to googling the difference between them and did not get a clear answer. Which one of these have the best performance with small to medium XML files. Thanks
C# – the difference between Linq to XML Descendants and Elements
clinq-to-xmlnetxml
Related Topic
- C# – What are the correct version numbers for C#
- C# – the difference between a field and a property
- .net – Difference between decimal, float and double in .NET
- C# – Difference Between Select and SelectMany
- C# – How to remedy “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning
- Php – How to parse and process HTML/XML in PHP
- C# – a NullReferenceException, and how to fix it
Best Answer
Elements
finds only those elements that are direct descendents, i.e. immediate children.Descendants
finds children at any level, i.e. children, grand-children, etc...Here is an example demonstrating the difference:
Code:
Result:
If you know that the elements you want are immediate children then you will get better performance if you use
Elements
instead ofDescendants
.