Get Last Element in C# using XElement

前端 未结 5 920
一向
一向 2020-12-07 04:35

I have a XML feed loaded in an XElement.

The structure is





         


        
5条回答
  •  Happy的楠姐
    2020-12-07 05:12

    Try this:

    rootElement.Descendants().Last()
    

    If you aren't sure there'll be any, you could also use LastOrDefault(). If there might be other elements besides within the , there's an overload of Descendants that will let you find just the posts you're looking for.

提交回复
热议问题