C#中的Boolean.TryParse()方法
C#中的Boolean.TryParse()方法用于将指定的逻辑值的字符串表示形式转换为其等效的布尔值。
语法
以下是语法-
public static bool TryParse (string val out bool result);
示例
现在让我们看一个实现Boolean.TryParse()方法的示例-
using System;
public class Demo {
public static void Main(){
bool val;
bool flag;
val = Boolean.TryParse("true", out flag);
Console.WriteLine("Result = "+val);
}
}输出结果
这将产生以下输出-
Result = True
示例
现在让我们来看另一个实现Boolean.TryParse()方法的示例-
using System;
public class Demo {
public static void Main(){
bool val;
bool flag;
val = Boolean.TryParse("$", out flag);
Console.WriteLine("Result = "+val);
}
}输出结果
这将产生以下输出-
Result = False
热门推荐
10 祝福语年轻回复文案简短
11 关云生字祝福语简短
12 对同事简短生日祝福语
13 收到公公生日祝福语简短
14 结婚婚庆祝福语简短
15 祝福语勤奋大全简短英语
16 新大学开学祝福语简短
17 对同学祝福语 简短独特
18 给孙子祝福语简短独特