Cast the value of XAttribute to a Boolean in CSharp

Description

The following code shows how to cast the value of XAttribute to a Boolean.

Example


   /*from   w ww.  ja  v a 2 s  .c  o m*/
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass{
   public static void Main(){
        XElement root = new XElement("Root", 
            new XAttribute("BoolValue", true)
        );
        bool bv = (bool)root.Attribute("BoolValue");
        Console.WriteLine("(bool)BoolValue={0}", bv);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style