+ 2
String to bool (need help)
I would like to get user Input true or false, but i don't know how to do it. And Convert.ToBool doesn't work. Some ideas ?
3 Respostas
+ 4
Maybe you meant to use Convert.ToBoolean()?
https://docs.microsoft.com/en-us/dotnet/api/system.convert.toboolean
+ 3
bool a;
String b = ...;
a = b.Equals("true");
+ 1
String st = args[0];
if(st.compareTo(”true”)==0 || st.compareTo(”false”)==0)
{
boolean b=Boolean.parseBoolean(st);
System.out.println(”” + b);
}
else
System.out.println(”not a boolean value”);
}
The above program is considering strings
If the string is either true or false
It will be converted to boolean and printed it
Otherwise, it is printing a warning message
Not a boolean value
This code is as per java which is similar to c#