Is there an easy way for me to convert bool true or false to the string "True" or "False". I know that I can do this with some, if the logic, but I wonder if there is something even simpler.
The Boolean structure has a ToString() method. So:
ToString()
bool b = true; Console.WriteLine(b.ToString());
Call ToString ()
System.Console.WriteLine(false.ToString()); System.Console.WriteLine(true.ToString());
If you mean true and false , you can use Convert.ToString
true
false
Convert.ToString
Convert.ToString(true) // "True"
EDIT : mattn has a better answer, I was translating code from VB where the true keyword did not have a ToString() method.
To simply print βTrueβ / βFalse,β readonly's built-in static fields in Boolean type:
Boolean
string falseString = bool.FalseString; string trueString = bool.TrueString;
Not that the bools value could change in the future or directly answer the OP question, but simply by adding some related information.
http://msdn.microsoft.com/en-us/library/system.boolean_fields(v=vs.100).aspx
Source: https://habr.com/ru/post/891064/More articles:Quick list search - listGarbage collection tool for dalvik - garbage-collectionGoogle cdn jQuery mobile - jquery-mobileNeed Help Defining / Understanding Java EE "Stack" - javaShould Enum class file names be added to "Enum"? - enumsData normalization and recording - designhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/891066/css-to-only-allow-selection-of-text-on-a-webpage&usg=ALkJrhipBfG6IC8QaPEWTl8xJKOQqDzEqgHow to find syntax error - wolfram-mathematicaAS3 How to start only on the x axis? - actionscript-3Adding jdbc driver to classpath - javaAll Articles