我在 XElement 中加载了一个 XML 提要。
结构是
<root>
<post></post>
<post></post>
<post></post>
<post></post>
.
.
.
.
<post></post>
</root>
我想直接获取Last post的值。我如何在 C# 中使用 XElement 来做到这一点。
谢谢。
最佳答案
或者试试这个来获取 XElement:
XDocument doc = XDocument.Load("yourfile.xml");
XElement root = doc.Root;
Console.WriteLine(root.Elements("post").Last());
关于c# - 使用 XElement 在 C# 中获取最后一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7884804/