- value
- The string to be converted.
true if value equals bool.TrueString; false if value equals bool.FalseString.
Type Reason ArgumentNullException value is a null reference. FormatException value is not equal to bool.TrueString or bool.FalseString.
Documentation for this section has not yet been entered.
The following example demonstrates converting string values to bool values.
C# Example
using System; class ConvertBoolTest { static public void Main() { string string0 = Boolean.TrueString; string string1 = Boolean.FalseString; string string2 = "foo"; //This is an invalid Boolean. bool bool0 = Convert.ToBoolean(string0); bool bool1 = Convert.ToBoolean(string1); Console.WriteLine("(string) {0} as bool = {1}",string0,bool0); Console.WriteLine("(string) {0} as bool = {1}",string1,bool1); bool bool2 = Convert.ToBoolean(string2); //Throws an exception. Console.WriteLine("(string) {0} as bool = {1}",string2,bool2); } }The output is
Example
(string) True as bool = True (string) False as bool = False Unhandled Exception: System.FormatException: String was not recognized as a valid Boolean. at System.Boolean.Parse(String value) at Convert.ToBoolean(String value) at ConvertBoolTest.Main() in C:\ECMAExamples\ConvertString.cs:line 12
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0