CSharp - Cast XElement to the Node Value's Type

Description

Cast XElement to the Node Value's Type

Demo

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

class Program/*w  w w.  j  av a2s  . co m*/
{
    static void Main(string[] args){
      XElement count = new XElement("Count", 12);
      Console.WriteLine(count);
      Console.WriteLine((int)count);

      XElement smoker = new XElement("Smoker", false);
      Console.WriteLine(smoker);
      Console.WriteLine((bool)smoker);

      XElement pi = new XElement("Pi", 3.1415926535);
      Console.WriteLine(pi);
      Console.WriteLine((double)pi);
    }
}

Result

Related Topic