Roi Shabtai
Roi Shabtai

Reputation: 3085

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.

Example: The xml used as log file. 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.

This is the Xml file: Xml file

Upvotes: 1

Views: 2032

Answers (1)

SLaks
SLaks

Reputation: 887479

.Last() exists in .Net 3.5 too.

You can write parent.Elements("ChildName").Last().

Upvotes: 4

Related Questions