To convert a specified value to an equivalent Boolean value, the code is as follows −
Example
using System;
using System.Globalization;
public class Demo {
public static void Main() {
CultureInfo cultures = new CultureInfo("en-US");
String str = "true";
Console.WriteLine("Converted bool value...");
bool res = Convert.ToBoolean(str, cultures);
Console.Write("{0}", res);
}
}Output
This will produce the following output −
Converted bool value... True
Example
Let us see another example −
using System;
using System.Globalization;
public class Demo {
public static void Main() {
CultureInfo cultures = new CultureInfo("es-ES", false);
String str = "false";
Console.WriteLine("Converted bool value...");
bool res = Convert.ToBoolean(str, cultures);
Console.Write("{0}", res);
}
}Output
This will produce the following output −
Converted bool value... False