CSharp - Creating XElement from LINQ statement

Description

Creating XElement from LINQ statement

Demo

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

class Program/*from   w w  w  .  j  a  v a  2s. c  om*/
{
    static void Main(string[] args){
          string[] names = { "Python", "Java", "C++", "Oracle" };
    
          XElement xNames = new XElement("Beatles",
                                         from n in names
                                         select new XElement("Name", n));
    
          names[3] = "Ringo";
    
          Console.WriteLine(xNames);
    }
}

Result

Related Topic