[英]Linq to Xml Get last Element - .Net 3.5
I'm trying to fetch the last element according to it's name. 我试图根据其名称获取最后一个元素。
I know there is Last() method on .Net 4, but since I must work with .Net 3.5 how can I find it. 我知道.Net 4上有Last()方法,但是由于我必须使用.Net 3.5,所以我怎么能找到它。
Example: The xml used as log file. 示例:用作日志文件的xml。 My method signature: GetLast(XName xName), and returns the last element specified (ExecutionReport, Scenario, Function etc.) I would like to get this element in order to add element afterwards. 我的方法签名:GetLast(XName xName),并返回指定的最后一个元素(ExecutionReport,Scenario,Function等)。我想获取此元素以便随后添加元素。
This is the Xml file: 这是Xml文件:
.Last()
exists in .Net 3.5 too. .Last()
存在于.Net 3.5中。
You can write parent.Elements("ChildName").Last()
. 您可以编写parent.Elements("ChildName").Last()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.