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

CsharpServer Side ProgrammingProgramming

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
raja
Published on 09-Dec-2019 10:35:16
Advertisements