C# bool.TrueString and FalseString

TrueString, FalseString. Truth has a string representation. The bool.TrueString and bool.FalseString fields provide the string literals "True" and "False" for English. By using these fields, we represent truth values.String LiteralBool
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.Readonly

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 uses 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.True, False
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.
© 2007-2020 Sam Allen. Every person is special and unique. Send bug reports to
Dot Net Perls