Why does Boolean.ToString output “True” and not “true”

Only people from Microsoft can really answer that question. However, I’d like to offer some fun facts about it 😉

First, this is what it says in MSDN about the Boolean.ToString() method:

Return Value

Type: System.String

TrueString if the value of this
instance is true, or FalseString if
the value of this instance is false.

Remarks

This method returns the
constants “True” or “False”. Note that
XML is case-sensitive, and that the
XML specification recognizes “true”
and “false” as the valid set of
Boolean values. If the String object
returned by the ToString() method
is to be written to an XML file, its
String.ToLower method should be
called first to convert it to
lowercase.

Here comes the fun fact #1: it doesn’t return TrueString or FalseString at all. It uses hardcoded literals “True” and “False”. Wouldn’t do you any good if it used the fields, because they’re marked as readonly, so there’s no changing them.

The alternative method, Boolean.ToString(IFormatProvider) is even funnier:

Remarks

The provider parameter is reserved. It does not participate in the execution of this method. This means that the Boolean.ToString(IFormatProvider) method, unlike most methods with a provider parameter, does not reflect culture-specific settings.

What’s the solution? Depends on what exactly you’re trying to do. Whatever it is, I bet it will require a hack 😉

Leave a Comment