Convert.ToBoolean(QUOT; 1 QUOT;)抛出异常System.Format在C# [英] Convert.ToBoolean("1") throws System.Format Exception in C#
本文介绍了Convert.ToBoolean(QUOT; 1 QUOT;)抛出异常System.Format在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么
Convert.ToBoolean("1")
抛出一个 System.FormatException
?
我应该如何使用这种转换进行呢?
How should I proceed with this conversion?
推荐答案
是的,这是的如记录:
[引发] FormatException [IF]值不等于TrueString或FalseString。
[throws] FormatException [if] value is not equal to TrueString or FalseString.
TrueString
是真和 FalseString
是假。
如果要检测一个字符串是否为1或没有,使用这段代码:
If you want to detect whether a string is "1" or not, use this code:
bool foo = text == "1";
这篇关于Convert.ToBoolean(QUOT; 1 QUOT;)抛出异常System.Format在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文