How do I convert string to Boolean value type?
Category: System, viewed: 2K 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();
}
}
}