I am tempted to use an if ... else ...
but I am wondering if there's an easier way? I need to display the true or false result in a message box.
The bool.ToString
method already does what you want.
This method returns the constants "True" or "False".
However in practice it is not that often that you need to explicitly call ToString
directly from your code. If you are already writing a string then the easiest way is to use concatenation:
string message = "The result is " + b;
This compiles to a call to string.Concat
and this calls the ToString
method for you.
In some situations it can be useful to use String.Format
, and again the ToString
method is called for you:
string message = string.Format("The result is {0}. Try again?", b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With