Convert.ToBoolean
#1
Posted 28 February 2012 - 09:31 PM
#2
Posted 28 February 2012 - 09:40 PM
bool.TrueString.Equals("true")or this:
true.ToString().Equals("true")
#3
Posted 28 February 2012 - 10:23 PM
Found these but their not exactly perfect either:
bool.TrueString.Equals("true")or this:
true.ToString().Equals("true")
Thank you for your reply. But I think both of those will always give me a true and they can't help evaluate a string type variable.
#4
Posted 29 February 2012 - 01:46 AM
Thank you for your reply. But I think both of those will always give me a true and they can't help evaluate a string type variable.
Could define your own "convert to boolean" method:
public static bool ToBoolean(string str) { if (str == bool.TrueString) { return true; } if (str == bool.FalseString) { return false; } throw new InvalidOperationException("String was not a bool"); }
#5
Posted 29 February 2012 - 05:35 AM
Is there a bool.Parse() method?string test = "true";
bool test2 = (test.ToLower() == "true");
Since there is no Convert.ToBoolean, what is the solution?
Regards,
Mark
To be or not to be = 0xFF
Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life
Follow @nevynuk on Twitter
#6
Posted 29 February 2012 - 03:59 PM
Could define your own "convert to boolean" method:
public static bool ToBoolean(string str) { if (str == bool.TrueString) { return true; } if (str == bool.FalseString) { return false; } throw new InvalidOperationException("String was not a bool"); }
There is a StackOverflow article that is worth reading about 'Why does Boolean.ToString output “True” and not “true”'. Great discussion.
For what I understood, the string has to be "True" and "False", and "true" and "false" are not valid.
http://stackoverflow...ue-and-not-true
#7
Posted 29 February 2012 - 08:00 PM
Yes they will but I meant for you to replace the literal string "true" with the string variable you wish to test. Using your nomenclature it becomes like so:Thank you for your reply. But I think both of those will always give me a true and they can't help evaluate a string type variable.
string test = "true"; bool test2 = bool.TrueString.Equals(test);
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users