Lower case Boolean.ToString() value

You can also do this which feels syntactically cleaner than true.ToString().ToLower() (in my opinion):

Json.Encode(true);

However under the hood this has far more overhead than using the .ToString.ToLower() implementation.

Json.Encode(object value) has much more error handling as it needs to account for the possibility of more complex objects being passed as arguments.

I did a little benchmarking on this to see what the difference actually is, and on my toaster of a dev box:

var sw0 = Stopwatch.StartNew();
sw0.Stop();

var sw1 = Stopwatch.StartNew();
var t1 = System.Web.Helpers.Json.Encode(true);
var e1 = sw1.ElapsedMilliseconds; // returns 6-9

var sw2 = Stopwatch.StartNew();
var t2 = true.ToString().ToLower();
var e2 = sw2.ElapsedMilliseconds; // returns 0

So really the impact isn't huge for a one off.


If you only want this for one bool variable you should use @Mohamed 's method. Else you can create an extension method (as you already said yourself):

public static class Extensions
{
    public static string ToLowerString(this bool _bool)
    {
        return _bool.ToString().ToLower();
    }
}

Then to use it:

public static void Main()
{
    bool testBoolean = true;
    Console.WriteLine(testBoolean.ToLowerString());
}

Why don't you try the following

public string MyStringBool
{
    get { return MyBool ? "true" : "false" ; }
}