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.

4

Best Answer


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

bool b = true;Console.WriteLine(b.ToString());

Call ToString()

System.Console.WriteLine(false.ToString());System.Console.WriteLine(true.ToString());

If you mean the values true and false you can use Convert.ToString

Convert.ToString(true) // "True"

EDIT: mattn has the better answer, I was translating code from VB where the True keyword did not have a ToString() method.

To simply print "True" / "False", there are built in static readonly fields on Boolean type:

string falseString = bool.FalseString;string trueString = bool.TrueString;

Not that the value of bools might change in future or directly answers OP's question, but just adding some related info.

http://msdn.microsoft.com/en-us/library/system.boolean_fields(v=vs.100).aspx