Convert double to Boolean value in CSharp

Description

The following code shows how to convert double to Boolean value.

Example


using System;/*from w  w w . j a  v  a  2s .  co m*/
using System.Globalization;

public class Example
{
   public static void Main()
   {
            double doubleVal = 2.0;

      bool  boolVal;
      boolVal = System.Convert.ToBoolean(doubleVal);
      System.Console.WriteLine("{0} as a Boolean is: {1}.",
        doubleVal, boolVal);


      doubleVal = System.Convert.ToDouble(boolVal);
      System.Console.WriteLine("{0} as a double is: {1}.",boolVal, doubleVal);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var