Computer >> Computer tutorials >  >> Programming >> C#

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

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

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