Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert bool true or false to string "True" or "False"

Tags:

c#

Is there a simple way for me to convert bool true or false to string "True" or "False". I know I can do this with some if logic but I am wondering if there is something even simpler.

like image 949
Jonathan S Avatar asked Jun 22 '11 00:06

Jonathan S


People also ask

Can we convert bool to string?

To convert Boolean to String in Java, use the toString() method. For this, firstly, we have declared two booleans. String str1 = new Boolean(bool1). toString(); String str2 = new Boolean(bool2).

How do you change a boolean from true to false?

Method 1: Using the logical NOT operator: The logical NOT operator in Boolean algebra is used to negate an expression or value. Using this operator on a true value would return false and using it on a false value would return true. This property can be used to toggle a boolean value.

Can we convert boolean to string in Python?

To convert boolean to string in python, we will use str(bool) and then it will be converted to string.


2 Answers

The Boolean structure has a ToString() method. So:

bool b = true;
Console.WriteLine(b.ToString());
like image 149
Justin Simon Avatar answered Oct 20 '22 01:10

Justin Simon


Call ToString()

System.Console.WriteLine(false.ToString());
System.Console.WriteLine(true.ToString());
like image 20
mattn Avatar answered Oct 19 '22 23:10

mattn