Convert the specified string representation of a logical value to its Boolean equivalent in C#



To convert the specified string representation of a logical value to its Boolean equivalent, the code is as follows −

Example

 Live Demo

using System;
public class Demo {
   public static void Main(){
      bool val;
      bool flag;
      val = Boolean.TryParse("true", out flag);
      Console.WriteLine("Result = "+val);
   }
}

Output

This will produce the following output −

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      bool val; bool flag;
      val = Boolean.TryParse("$", out flag);
      Console.WriteLine("Result = "+val);
   }
}

Output

This will produce the following output −

Result = False

Advertisements