How do I convert string to Boolean value type?

Category: System, viewed: 324 time(s).

The Parse method of Boolean can be explained as follow. When calling Boolean.Parse, if a string value doesn't contains either the static properties Boolean.FalseString, Boolean.TrueString, or the string literals "false" or "true" (which are case-insensitive), a FormatException exception is thrown.

Passing in a null for the SourceString parameter throws an ArgumentNullException exception.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kodecsharp.Example.System
{
    public class StringToBoolean
    {
        public static void Main(string[] args)
        {
            string t = "true";
            string f = "FALSE";

            //
            // Converting string of boolean value to Boolean can be done
            // by calling the Parse method of the Boolean object.
            //
            Boolean tValue = Boolean.Parse(t);
            Boolean fValue = Boolean.Parse(f);

            Console.Out.WriteLine("T = " + tValue);
            Console.Out.WriteLine("F = " + fValue);

            Console.ReadLine();
        }
    }
}
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Our Friends

Statistics

Locations of visitors to this page