XElement element = new XElement("root", new XElement("item", "1"), new XElement("item", "2"), new XElement("item", "3")); XElement lastElement = element.LastElement();
XDocument doc = XDocument.Load("data.xml"); XElement lastElement = doc.Root.LastElement();In this example, an `XDocument` called `doc` is loaded from an XML file called "data.xml". The `LastElement()` method is then called on the root element of the document to retrieve the last child element. This method is part of the `System.Xml.Linq` namespace, which is included in the .NET Framework Class Library.