Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XContainer.LastNode Property

Get the last child node of this node.

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

public XNode LastNode { get; }

Property Value

Type: System.Xml.Linq.XNode
An XNode containing the last child node of the XContainer.

The following example creates an element that contains child elements. It then gets the last child node of the parent element.

XElement xmlTree = new XElement("Root",
    new XElement("Child1", 1),
    new XElement("Child2", 2),
    new XElement("Child3", 3),
    new XElement("Child4", 4),
    new XElement("Child5", 5)
);
XNode lastNode = xmlTree.LastNode;
Console.WriteLine(lastNode);

This example produces the following output:

<Child5>5</Child5>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft