XElement root = new XElement("root"); root.AddAnnotation("This is a root element");
XElement element = new XElement("person", new XElement("firstname", "John"), new XElement("lastname", "Doe")); element.AddAnnotation(new Person { Age = 30, Gender = "male" });This example shows how to add a custom object (Person) as an annotation to an XML element. The Person object has two properties: Age and Gender. The XElement class is part of the System.Xml.Linq namespace, which is included in the .NET Framework.