Specified object to convert the Boolean. - CSharp System

CSharp examples for System:Converter

Description

Specified object to convert the Boolean.

Demo Code


using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;/*from  w w  w  .  jav  a  2 s .c  om*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        /// <summary>
        /// Specified object to convert the Boolean.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Boolean? ToBoolean(Object value)
        {
            Boolean? rt = null;
            Boolean x;

            if (value == null)
            { return null; }

            if (Boolean.TryParse(ToStringOrEmpty(value), out x))
            {
                rt = x;
            }
            return rt;
        }
        /// <summary>
        /// Specified object to convert the Boolean.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static Boolean ToBoolean(Object value, Boolean defaultValue)
        {
            return ToBoolean(value) ?? defaultValue;
        }
}

Related Tutorials