Mega Code Archive

 
Categories / C# Book / 05 LINQ XML
 

0528 Create XElement with XML structure similar structure

using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; class Program { static void Main() { XElement customer = new XElement("customer", new XAttribute("id", 123), new XElement("firstname", "Jack"), new XElement("lastname", "Smith", new XComment("It is a name") ) ); Console.WriteLine(customer); } } The output: JackSmith