Boolean - ToBinary
A bool extension method that convert this object into a binary representation.
public static void Main() { bool thisTrue = true; bool thisFalse = false; // C# Extension Method: Boolean - ToBinary byte result1 = thisTrue.ToBinary(); byte result2 = thisFalse.ToBinary(); Console.WriteLine("value1 = {0}", result1); Console.WriteLine("value2 = {0}", result2); }
View Source
using System; public static partial class Extensions { /// <summary> /// A bool extension method that convert this object into a binary representation. /// </summary> /// <param name="this">The @this to act on.</param> /// <returns>A binary represenation of this object.</returns> public static byte ToBinary(this bool @this) { return Convert.ToByte(@this); } }