CSharp - Using Functional Construction to Create an XML

Introduction

We passed two XElement objects as parameter value, and each of which becomes a child element.

We constructed the FirstName and LastName elements, instead of specifying multiple child objects.

Demo

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Program/*  w w w  .  ja  v a2  s .  c  o m*/
{
    static void Main(string[] args)
    {
        XElement xBook = new XElement("Book",
        new XElement("FirstName", "Joe"),
        new XElement("LastName", "Ruby"));

        Console.WriteLine(xBook.ToString());

    }
}

Result

Related Topic