Convert.ToBoolean(String, IFormatProvider) Method in C#


The Convert.ToBoolean() method in C# is used to convert a specified value to an equivalent Boolean value.

Syntax

Following is the syntax −

public static bool ToBoolean (string val, IFormatProvider provider);

Above, Val is a string that contains the value of either TrueString or FalseString, whereas the provider is an object that supplies culture-specific formatting information.

Example

Let us now see an example to implement the Convert.ToBoolean() method −

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

Updated on: 05-Nov-2019

200 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements