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/*  w  ww .  j av a 2s  .c o  m*/
{
    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