CSharp - Creating an Element and Assigning a String As Its Value

Description

Creating an Element and Assigning a String As Its Value

Demo

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

class Program//ww  w  .  ja  v  a2s.com
{
    static void Main(string[] args){
        
        XElement xFirstName = new XElement("FirstName", "Joe");
        Console.WriteLine(xFirstName);
    }
}

Result

"Joe" is converted into an XText object, and that is added to the XElement object.

Related Topic