Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

XContainer.LastNode Property

Get the last child node of this node.

Namespace:  System.Xml.Linq
Assemblies:   System.Xml.Linq (in System.Xml.Linq.dll)
  System.Xml.XDocument (in System.Xml.XDocument.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