在 C# 中将逻辑值的指定字符串表示形式转换为其布尔等效值

csharpserver side programmingprogramming

要将逻辑值的指定字符串表示形式转换为其布尔等效值,代码如下 −

示例

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

输出

这将产生以下输出 −

示例

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

输出

这将产生以下输出 −

Result = False

相关文章