Why does
Convert.ToBoolean("1")
throw a System.FormatException
?
How should I proceed with this conversion?
Yes, this is as documented:
[throws] FormatException [if] value is not equal to TrueString or FalseString.
TrueString
is "True" and FalseString
is "False".
If you want to detect whether a string is "1" or not, use this code:
bool foo = text == "1";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With