C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
String LiteralBool Type: If True, False
Example. These two fields are implemented as public static readonly fields. This means that a memory location must be accessed each time you use them. Also, they return "True" and "False" in this program. But this is not guaranteed.
Note: In other locales, it is possible they will return other strings. We compare these fields and use them just like normal strings.
C# program that demonstrates TrueString and FalseString using System; class Program { static void Main() { // Write values of these properties. Console.WriteLine(bool.TrueString); Console.WriteLine(bool.FalseString); Console.WriteLine(); Console.WriteLine(bool.TrueString == "True"); Console.WriteLine(bool.FalseString == "False"); } } Output True False True True
Literals. In programming, truth can be represented directly with the true and false literals. The string representation is available with the TrueString and FalseString fields. More information about boolean literals is available.
Summary. Programs often need these strings. TrueString and FalseString are a useful pair of readonly members. They represent truth values in string format. They provide indirection and abstraction over directly using string literals.