System.Convert Class

public sealed class Convert

Base Types

Object
  Convert

Assembly

mscorlib

Library

BCL

Summary

Performs conversions between base data types.

Description

The following table shows conversions from source types to destination types. The first column contains the source types. The remaining columns indicate the destination types the source can be converted to. An 'x' indicates the Convert class implements the conversion. [Note: the column headers correspond precisely, in order, to the source types in the first column, but have been abbreviated to fit.]

TypeBool
Booleanx
Bytex
Char
DateTime
Decimalx
Doublex
Int16x
Int32x
Int64x
SBytex
Singlex
Stringx
UInt16x
UInt32x
UInt64x
If the conversion of a numeric type results in a loss of precision, no exception is thrown. However, an exception is thrown if the conversion result is a value that is larger than that which can be represented by the destination type. For example, when a Double is converted to a Single, a loss of precision might occur but no exception is thrown. However, if the magnitude of the Double is too large to be represented by a Single, a OverflowException is thrown.

See Also

System Namespace

Members

Convert Methods

Convert.ToBoolean(System.Decimal) Method
Convert.ToBoolean(double) Method
Convert.ToBoolean(float) Method
Convert.ToBoolean(System.String) Method
Convert.ToBoolean(ulong) Method
Convert.ToBoolean(long) Method
Convert.ToBoolean(uint) Method
Convert.ToBoolean(int) Method
Convert.ToBoolean(ushort) Method
Convert.ToBoolean(short) Method
Convert.ToBoolean(byte) Method
Convert.ToBoolean(sbyte) Method
Convert.ToBoolean(bool) Method
Convert.ToByte(System.String) Method
Convert.ToByte(System.Decimal) Method
Convert.ToByte(double) Method
Convert.ToByte(float) Method
Convert.ToByte(ulong) Method
Convert.ToByte(long) Method
Convert.ToByte(uint) Method
Convert.ToByte(int) Method
Convert.ToByte(ushort) Method
Convert.ToByte(short) Method
Convert.ToByte(sbyte) Method
Convert.ToByte(bool) Method
Convert.ToByte(byte) Method
Convert.ToByte(char) Method
Convert.ToByte(System.String, System.IFormatProvider) Method
Convert.ToChar(System.String) Method
Convert.ToChar(ulong) Method
Convert.ToChar(long) Method
Convert.ToChar(uint) Method
Convert.ToChar(int) Method
Convert.ToChar(ushort) Method
Convert.ToChar(short) Method
Convert.ToChar(byte) Method
Convert.ToChar(sbyte) Method
Convert.ToChar(char) Method
Convert.ToDateTime(System.DateTime) Method
Convert.ToDateTime(System.String) Method
Convert.ToDateTime(System.String, System.IFormatProvider) Method
Convert.ToDecimal(bool) Method
Convert.ToDecimal(System.Decimal) Method
Convert.ToDecimal(System.String, System.IFormatProvider) Method
Convert.ToDecimal(System.String) Method
Convert.ToDecimal(double) Method
Convert.ToDecimal(float) Method
Convert.ToDecimal(ulong) Method
Convert.ToDecimal(long) Method
Convert.ToDecimal(uint) Method
Convert.ToDecimal(int) Method
Convert.ToDecimal(ushort) Method
Convert.ToDecimal(short) Method
Convert.ToDecimal(byte) Method
Convert.ToDecimal(sbyte) Method
Convert.ToDouble(double) Method
Convert.ToDouble(float) Method
Convert.ToDouble(ulong) Method
Convert.ToDouble(long) Method
Convert.ToDouble(uint) Method
Convert.ToDouble(int) Method
Convert.ToDouble(ushort) Method
Convert.ToDouble(short) Method
Convert.ToDouble(byte) Method
Convert.ToDouble(sbyte) Method
Convert.ToDouble(bool) Method
Convert.ToDouble(System.Decimal) Method
Convert.ToDouble(System.String) Method
Convert.ToDouble(System.String, System.IFormatProvider) Method
Convert.ToInt16(System.Decimal) Method
Convert.ToInt16(System.String) Method
Convert.ToInt16(System.String, System.IFormatProvider) Method
Convert.ToInt16(double) Method
Convert.ToInt16(float) Method
Convert.ToInt16(ulong) Method
Convert.ToInt16(long) Method
Convert.ToInt16(short) Method
Convert.ToInt16(uint) Method
Convert.ToInt16(int) Method
Convert.ToInt16(ushort) Method
Convert.ToInt16(byte) Method
Convert.ToInt16(sbyte) Method
Convert.ToInt16(char) Method
Convert.ToInt16(bool) Method
Convert.ToInt32(bool) Method
Convert.ToInt32(System.String, System.IFormatProvider) Method
Convert.ToInt32(System.String) Method
Convert.ToInt32(System.Decimal) Method
Convert.ToInt32(double) Method
Convert.ToInt32(float) Method
Convert.ToInt32(ulong) Method
Convert.ToInt32(long) Method
Convert.ToInt32(int) Method
Convert.ToInt32(uint) Method
Convert.ToInt32(ushort) Method
Convert.ToInt32(short) Method
Convert.ToInt32(byte) Method
Convert.ToInt32(sbyte) Method
Convert.ToInt32(char) Method
Convert.ToInt64(char) Method
Convert.ToInt64(bool) Method
Convert.ToInt64(sbyte) Method
Convert.ToInt64(byte) Method
Convert.ToInt64(short) Method
Convert.ToInt64(ushort) Method
Convert.ToInt64(int) Method
Convert.ToInt64(uint) Method
Convert.ToInt64(ulong) Method
Convert.ToInt64(long) Method
Convert.ToInt64(float) Method
Convert.ToInt64(double) Method
Convert.ToInt64(System.Decimal) Method
Convert.ToInt64(System.String) Method
Convert.ToInt64(System.String, System.IFormatProvider) Method
Convert.ToSByte(bool) Method
Convert.ToSByte(sbyte) Method
Convert.ToSByte(char) Method
Convert.ToSByte(byte) Method
Convert.ToSByte(short) Method
Convert.ToSByte(ushort) Method
Convert.ToSByte(int) Method
Convert.ToSByte(uint) Method
Convert.ToSByte(long) Method
Convert.ToSByte(ulong) Method
Convert.ToSByte(float) Method
Convert.ToSByte(double) Method
Convert.ToSByte(System.Decimal) Method
Convert.ToSByte(System.String) Method
Convert.ToSByte(System.String, System.IFormatProvider) Method
Convert.ToSingle(System.String, System.IFormatProvider) Method
Convert.ToSingle(System.String) Method
Convert.ToSingle(System.Decimal) Method
Convert.ToSingle(double) Method
Convert.ToSingle(float) Method
Convert.ToSingle(ulong) Method
Convert.ToSingle(long) Method
Convert.ToSingle(uint) Method
Convert.ToSingle(int) Method
Convert.ToSingle(ushort) Method
Convert.ToSingle(short) Method
Convert.ToSingle(byte) Method
Convert.ToSingle(sbyte) Method
Convert.ToSingle(bool) Method
Convert.ToString(uint, System.IFormatProvider) Method
Convert.ToString(long) Method
Convert.ToString(long, System.IFormatProvider) Method
Convert.ToString(ulong) Method
Convert.ToString(ulong, System.IFormatProvider) Method
Convert.ToString(float) Method
Convert.ToString(float, System.IFormatProvider) Method
Convert.ToString(double) Method
Convert.ToString(double, System.IFormatProvider) Method
Convert.ToString(System.Decimal) Method
Convert.ToString(System.Decimal, System.IFormatProvider) Method
Convert.ToString(System.DateTime) Method
Convert.ToString(System.DateTime, System.IFormatProvider) Method
Convert.ToString(uint) Method
Convert.ToString(int, System.IFormatProvider) Method
Convert.ToString(int) Method
Convert.ToString(ushort, System.IFormatProvider) Method
Convert.ToString(ushort) Method
Convert.ToString(short, System.IFormatProvider) Method
Convert.ToString(short) Method
Convert.ToString(byte, System.IFormatProvider) Method
Convert.ToString(byte) Method
Convert.ToString(sbyte, System.IFormatProvider) Method
Convert.ToString(sbyte) Method
Convert.ToString(char) Method
Convert.ToString(bool) Method
Convert.ToString(System.String) Method
Convert.ToUInt16(System.String, System.IFormatProvider) Method
Convert.ToUInt16(System.String) Method
Convert.ToUInt16(System.Decimal) Method
Convert.ToUInt16(double) Method
Convert.ToUInt16(float) Method
Convert.ToUInt16(ulong) Method
Convert.ToUInt16(long) Method
Convert.ToUInt16(uint) Method
Convert.ToUInt16(ushort) Method
Convert.ToUInt16(int) Method
Convert.ToUInt16(short) Method
Convert.ToUInt16(byte) Method
Convert.ToUInt16(sbyte) Method
Convert.ToUInt16(char) Method
Convert.ToUInt16(bool) Method
Convert.ToUInt32(bool) Method
Convert.ToUInt32(char) Method
Convert.ToUInt32(sbyte) Method
Convert.ToUInt32(byte) Method
Convert.ToUInt32(short) Method
Convert.ToUInt32(ushort) Method
Convert.ToUInt32(int) Method
Convert.ToUInt32(uint) Method
Convert.ToUInt32(long) Method
Convert.ToUInt32(ulong) Method
Convert.ToUInt32(float) Method
Convert.ToUInt32(double) Method
Convert.ToUInt32(System.Decimal) Method
Convert.ToUInt32(System.String) Method
Convert.ToUInt32(System.String, System.IFormatProvider) Method
Convert.ToUInt64(System.String, System.IFormatProvider) Method
Convert.ToUInt64(System.String) Method
Convert.ToUInt64(System.Decimal) Method
Convert.ToUInt64(double) Method
Convert.ToUInt64(float) Method
Convert.ToUInt64(ulong) Method
Convert.ToUInt64(long) Method
Convert.ToUInt64(uint) Method
Convert.ToUInt64(int) Method
Convert.ToUInt64(ushort) Method
Convert.ToUInt64(short) Method
Convert.ToUInt64(byte) Method
Convert.ToUInt64(sbyte) Method
Convert.ToUInt64(char) Method
Convert.ToUInt64(bool) Method


Convert.ToBoolean(System.Decimal) Method

public static bool ToBoolean(decimal value);

Summary

Converts a Decimal to a Boolean.

Parameters

value
The Decimal value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Example

The following example demonstrates converting Decimal values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        decimal decimal0 = 0m;
        decimal decimal1 = 1m; 
        decimal decimal2 = -2m;
        bool bool0 = Convert.ToBoolean(decimal0);
        bool bool1 = Convert.ToBoolean(decimal1);
        bool bool2 = Convert.ToBoolean(decimal2);
        Console.WriteLine("(decimal) {0} as bool = {1}",decimal0,bool0);
        Console.WriteLine("(decimal) {0} as bool = {1}",decimal1,bool1);
        Console.WriteLine("(decimal) {0} as bool = {1}",decimal2,bool2);
    }
}
The output is

(decimal) 0 as bool = False

(decimal) 1 as bool = True

(decimal) -2 as bool = True

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(double) Method

public static bool ToBoolean(double value);

Summary

Converts a Double to a Boolean .

Parameters

value
The Double value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Example

The following example demonstrates converting Double values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        double double0 = 0.0;
        double double1 = 1.0; 
        double double2 = -2.0;
        bool bool0 = Convert.ToBoolean(double0);
        bool bool1 = Convert.ToBoolean(double1);
        bool bool2 = Convert.ToBoolean(double2);
        Console.WriteLine("(double) {0} as bool = {1}",double0,bool0);
        Console.WriteLine("(double) {0} as bool = {1}",double1,bool1);
        Console.WriteLine("(double) {0} as bool = {1}",double2,bool2);
    }
}
The output is

(double) 0 as bool = False

(double) 1 as bool = True

(double) -2 as bool = True

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(float) Method

public static bool ToBoolean(float value);

Summary

Converts a Single to a Boolean .

Parameters

value
The Single value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Example

The following example demonstrates converting Single values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        float float0 = 0.0f;
        float float1 = 1.0f; 
        float float2 = -2.0f;
        bool bool0 = Convert.ToBoolean(float0);
        bool bool1 = Convert.ToBoolean(float1);
        bool bool2 = Convert.ToBoolean(float2);
        Console.WriteLine("(float) {0} as bool = {1}",float0,bool0);
        Console.WriteLine("(float) {0} as bool = {1}",float1,bool1);
        Console.WriteLine("(float) {0} as bool = {1}",float2,bool2);
    }
}
The output is

(float) 0 as bool = False

(float) 1 as bool = True

(float) -2 as bool = True

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(System.String) Method

public static bool ToBoolean(string value);

Summary

Converts a String to a Boolean .

Parameters

value
The String to be converted.

Return Value

true if value equals System.Boolean.TrueString; false if value equals System.Boolean.FalseString.

Exceptions

Exception TypeCondition
ArgumentNullExceptionvalue is a null reference.
FormatExceptionvalue is not equal to System.Boolean.TrueString or System.Boolean.FalseString.

Example

The following example demonstrates converting String values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        string string0 = Boolean.TrueString;
        string string1 = Boolean.FalseString; 
        string string2 = "foo"; //This is an invalid Boolean.
        bool bool0 = Convert.ToBoolean(string0);
        bool bool1 = Convert.ToBoolean(string1);
        Console.WriteLine("(string) {0} as bool = {1}",string0,bool0);
        Console.WriteLine("(string) {0} as bool = {1}",string1,bool1);
        bool bool2 = Convert.ToBoolean(string2); //Throws an exception.
        Console.WriteLine("(string) {0} as bool = {1}",string2,bool2);
    }
}
The output is

(string) True as bool = True
(string) False as bool = False
Unhandled Exception: System.FormatException: String was not recognized as a valid Boolean.
      at System.Boolean.Parse(String value)
      at Convert.ToBoolean(String value)
      at ConvertBoolTest.Main() in C:\ECMAExamples\ConvertString.cs:line 12

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(ulong) Method

public static bool ToBoolean(ulong value);

Summary

Converts a UInt64 to a Boolean .

Parameters

value
The 64-bit unsigned integer value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToBoolean(System.Object)(Decimal).

Example

The following example demonstrates converting UInt64 values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        ulong ulong0 = 0;
        ulong ulong1 = 1; 
        bool bool0 = Convert.ToBoolean(ulong0);
        bool bool1 = Convert.ToBoolean(ulong1);
        Console.WriteLine("(ulong) {0} as bool = {1}",ulong0,bool0);
        Console.WriteLine("(ulong) {0} as bool = {1}",ulong1,bool1);
    }
}
The output is

(ulong) 0 as bool = False

(ulong) 1 as bool = True

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(long) Method

public static bool ToBoolean(long value);

Summary

Converts a Int64 to a Boolean .

Parameters

value
The 64-bit signed integer value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Example

The following example demonstrates converting Int64 values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        long long0 = 0;
        long long1 = 1; 
        long long2 = -2;
        bool bool0 = Convert.ToBoolean(long0);
        bool bool1 = Convert.ToBoolean(long1);
        bool bool2 = Convert.ToBoolean(long2);
        Console.WriteLine("(long) {0} as bool = {1}",long0,bool0);
        Console.WriteLine("(long) {0} as bool = {1}",long1,bool1);
        Console.WriteLine("(long) {0} as bool = {1}",long2,bool2);
    }
}
The output is

(long) 0 as bool = False

(long) 1 as bool = True

(long) -2 as bool = True

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(uint) Method

public static bool ToBoolean(uint value);

Summary

Converts a UInt32 to a Boolean .

Parameters

value
The 32-bit unsigned integer value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToBoolean(System.Object)(Int64).

Example

The following example demonstrates converting UInt32 values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        uint uint0 = 0;
        uint uint1 = 1; 
        bool bool0 = Convert.ToBoolean(uint0);
        bool bool1 = Convert.ToBoolean(uint1);
        Console.WriteLine("(uint) {0} as bool = {1}",uint0,bool0);
        Console.WriteLine("(uint) {0} as bool = {1}",uint1,bool1);
    }
}
The output is

(uint) 0 as bool = False

(uint) 1 as bool = True

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(int) Method

public static bool ToBoolean(int value);

Summary

Converts a Int32 to a Boolean .

Parameters

value
The 32-bit signed integer value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Example

The following example demonstrates converting Int32 values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        int int0 = 0;
        int int1 = 1; 
        int int2 = -2;
        bool bool0 = Convert.ToBoolean(int0);
        bool bool1 = Convert.ToBoolean(int1);
        bool bool2 = Convert.ToBoolean(int2);
        Console.WriteLine("(int) {0} as bool = {1}",int0,bool0);
        Console.WriteLine("(int) {0} as bool = {1}",int1,bool1);
        Console.WriteLine("(int) {0} as bool = {1}",int2,bool2);
    }
}
The output is

(int) 0 as bool = False

(int) 1 as bool = True

(int) -2 as bool = True

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(ushort) Method

public static bool ToBoolean(ushort value);

Summary

Converts a UInt16 to a Boolean .

Parameters

value
The 16-bit unsigned integer value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToBoolean(System.Object)(Int32).

Example

The following example demonstrates converting Int16 values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        ushort ushort0 = 0;
        ushort ushort1 = 1; 
        bool bool0 = Convert.ToBoolean(ushort0);
        bool bool1 = Convert.ToBoolean(ushort1);
        Console.WriteLine("(ushort) {0} as bool = {1}",ushort0,bool0);
        Console.WriteLine("(ushort) {0} as bool = {1}",ushort1,bool1);
    }
}
The output is

(ushort) 0 as bool = False

(ushort) 1 as bool = True

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(short) Method

public static bool ToBoolean(short value);

Summary

Converts a Int16 to a Boolean .

Parameters

value
The 16-bit signed integer value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Example

The following example demonstrates converting Byte values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        short short0 = 0;
        short short1 = 1; 
        short short2 = -2;
        bool bool0 = Convert.ToBoolean(short0);
        bool bool1 = Convert.ToBoolean(short1);
        bool bool2 = Convert.ToBoolean(short2);
        Console.WriteLine("(short) {0} as bool = {1}",short0,bool0);
        Console.WriteLine("(short) {0} as bool = {1}",short1,bool1);
        Console.WriteLine("(short) {0} as bool = {1}",short2,bool2);
    }
}
The output is

(short) 0 as bool = False

(short) 1 as bool = True

(short) -2 as bool = True

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(byte) Method

public static bool ToBoolean(byte value);

Summary

Converts a Byte to a Boolean .

Parameters

value
The Byte value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Example

The following example demonstrates converting Byte values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        byte byte0 = (byte) 0;
        byte byte1 = (Byte) 1; 
        bool bool0 = Convert.ToBoolean(byte0);
        bool bool1 = Convert.ToBoolean(byte1);
        Console.WriteLine("(byte) {0} as bool = {1}",byte0,bool0);
        Console.WriteLine("(byte) {0} as bool = {1}",byte1,bool1);
    }
}
The output is

(byte) 0 as bool = False

(byte) 1 as bool = True

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(sbyte) Method

public static bool ToBoolean(sbyte value);

Summary

Converts a SByte to a Boolean .

Parameters

value
The 8-bit signed integer value to be converted.

Return Value

true if value is non-zero; false if value is zero.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToBoolean(System.Object)(Int16).

Example

The following example demonstrates converting SByte values to Boolean values.

using System;
class ConvertBoolTest {
    static public void Main() {
        sbyte sbyte0 = (sbyte) 0;
        sbyte sbyte1 = (sbyte) 1; 
        sbyte sbyte2 = (sbyte) -2;
        bool bool0 = Convert.ToBoolean(sbyte0);
        bool bool1 = Convert.ToBoolean(sbyte1);
        bool bool2 = Convert.ToBoolean(sbyte2);
        Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte0,bool0);
        Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte1,bool1);
        Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte2,bool2);
    }
}
The output is

(sbyte) 0 as bool = False

(sbyte) 1 as bool = True

(sbyte) -2 as bool = True

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToBoolean(bool) Method

public static bool ToBoolean(bool value);

Summary

Converts a Boolean to a Boolean .

Parameters

value
The Boolean value to be converted.

Return Value

value is returned unchanged.

Description

[Note: This method is provided for completeness.]

See Also

System.Convert Class, System Namespace

Convert.ToByte(System.String) Method

public static byte ToByte(string value);

Summary

Converts a String representation of a number to a Byte .

Parameters

value
The String to be converted. The string is in the System.Globalization.NumberStyles.Integer style.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
ArgumentNullExceptionvalue is a null reference.
FormatExceptionvalue does not consist of an optional sign followed by one or more digits (zero through nine).
OverflowExceptionThe numeric value of value is greater than System.Byte.MaxValue or less than System.Byte.MinValue.

Example

The following example demonstrates converting String values to Byte values.

using System;
class ConvertByteTest {
    static public void Main() {
        string string0 = "+22";
        string string1 = "0"; 
        string string2 = "-1";
        byte byte0 = Convert.ToByte(string0);
        byte byte1 = Convert.ToByte(string1);
        Console.WriteLine("(string) {0} as byte = {1}",string0,byte0);
        Console.WriteLine("(string) {0} as byte = {1}",string1,byte1);
        byte byte2 = Convert.ToByte(string2);
        Console.WriteLine("(string) {0} as byte = {1}",string2,byte2);
    }
}
The output is

(string) +22 as byte = 22

(string) 0 as byte = 0

Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte.

at System.Byte.Parse(String s, NumberStyles style, IFormatProvider provider)

at System.Byte.Parse(String s)

at Convert.ToByte(String value)

at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertString.cs:line 11

See Also

System.Convert Class, System Namespace

Convert.ToByte(System.Decimal) Method

public static byte ToByte(decimal value);

Summary

Converts a Decimal to a Byte .

Parameters

value
The Decimal value to be converted.

Return Value

value as a Byte , rounded to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue or less than System.Byte.MinValue.

Description

Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. [Note: This process is known as banker's rounding.]

Example

The following example demonstrates converting Decimal values to Byte values.

using System;
class ConvertByteTest {
    static public void Main() {
        decimal decimal0 = 0.0m;
        decimal decimal1 = 1.5m;
        decimal decimal2 = 2.5m; 
        decimal decimal3 = -1.0m; 
        byte byte0 = Convert.ToByte(decimal0);
        byte byte1 = Convert.ToByte(decimal1);
        byte byte2 = Convert.ToByte(decimal2);
        Console.WriteLine("(decimal) {0} as byte = {1}",decimal0,byte0);
        Console.WriteLine("(decimal) {0} as byte = {1}",decimal1,byte1);
        Console.WriteLine("(decimal) {0} as byte = {1}",decimal2,byte2);

        byte byte3 = Convert.ToByte(decimal3); //Throws an exception.
        Console.WriteLine("(decimal) {0} as byte = {1}",decimal3,byte3);
    }
}
The output is

(decimal) 0 as byte = 0

(decimal) 1.5 as byte = 2

(decimal) 2.5 as byte = 2

Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte.

at System.Decimal.ToByte(Decimal value)

at Convert.ToByte(Decimal value)

at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertDecimal.cs:line 15

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToByte(double) Method

public static byte ToByte(double value);

Summary

Converts a Double to a Byte .

Parameters

value
The Double value to be converted.

Return Value

value as a Byte , rounded to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue or less than System.Byte.MinValue, or value is equal to one of System.Double.NaN, System.Double.PositiveInfinity, or System.Double.NegativeInfinity.

Description

Prior to the conversion, if value is halfway between two numbers, it is rounded to the number that has an even digit in the rightmost decimal position. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36

Example

The following example demonstrates converting Double values to Byte values.

using System;
class ConvertByteTest {
    static public void Main() {
        double double0 = 0.0;
        double double1 = 1.5;
        double double2 = 2.5; 
        double double3 = -1.0; 
        byte byte0 = Convert.ToByte(double0);
        byte byte1 = Convert.ToByte(double1);
        byte byte2 = Convert.ToByte(double2);
        Console.WriteLine("(double) {0} as byte = {1}",double0,byte0);
        Console.WriteLine("(double) {0} as byte = {1}",double1,byte1);
        Console.WriteLine("(double) {0} as byte = {1}",double2,byte2);

        byte byte3 = Convert.ToByte(double3); //Throws an exception.
        Console.WriteLine("(double) {0} as byte = {1}",double3,byte3);
    }
}
The output is

(double) 0 as byte = 0

(double) 1.5 as byte = 2

(double) 2.5 as byte = 2

Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte.

at Convert.ToByte(Int32 value)

at Convert.ToByte(Double value)

at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertDouble.cs:line 15

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToByte(float) Method

public static byte ToByte(float value);

Summary

Converts a Single to a Byte .

Parameters

value
The Single value to be converted.

Return Value

value as a Byte , rounded to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue or less than System.Byte.MinValue, or value is equal to one of System.Single.NaN, System.Single.PositiveInfinity, or System.Single.NegativeInfinity.

Description

Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6.

Example

The following example demonstrates converting Single values to Byte values.

using System;
class ConvertByteTest {
    static public void Main() {
        float float0 = 0.0f;
        float float1 = 1.5f;
        float float2 = 2.5f; 
        float float3 = -1.0f; 
        byte byte0 = Convert.ToByte(float0);
        byte byte1 = Convert.ToByte(float1);
        byte byte2 = Convert.ToByte(float2);
        Console.WriteLine("(float) {0} as byte = {1}",float0,byte0);
        Console.WriteLine("(float) {0} as byte = {1}",float1,byte1);
        Console.WriteLine("(float) {0} as byte = {1}",float2,byte2);

        byte byte3 = Convert.ToByte(float3); //Throws an exception.
        Console.WriteLine("(float) {0} as byte = {1}",float3,byte3);
    }
}
The output is

(float) 0 as byte = 0

(float) 1.5 as byte = 2

(float) 2.5 as byte = 2

Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte.

at Convert.ToByte(Int32 value)

at Convert.ToByte(Single value)

at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertFloat.cs:line 15

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToByte(ulong) Method

public static byte ToByte(ulong value);

Summary

Converts a UInt64 to a Byte .

Parameters

value
The 64-bit unsigned integer value to be converted.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToByte(System.Object)(Decimal).

Example

The following example demonstrates converting UInt64 values to Byte values.

using System;
class ConvertByteTest {
    static public void Main() {
        ulong ulong0 = 0;
        ulong ulong1 = 32000;
        byte byte0 = Convert.ToByte(ulong0);
        Console.WriteLine("(ulong) {0} as byte = {1}",ulong0,byte0);
        byte byte1 = Convert.ToByte(ulong1); //Throws an exception.
        Console.WriteLine("(ulong) {0} as byte = {1}",ulong1,byte1);
    }
}
The output is

(ulong) 0 as byte = 0

Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte.

at Convert.ToByte(UInt64 value)

at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertUInt64.cs:line 8

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToByte(long) Method

public static byte ToByte(long value);

Summary

Converts a Int64 to a Byte .

Parameters

value
The 64-bit signed integer value to be converted.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue or less than System.Byte.MinValue.

See Also

System.Convert Class, System Namespace

Convert.ToByte(uint) Method

public static byte ToByte(uint value);

Summary

Converts a UInt32 to a Byte .

Parameters

value
The 32-bit unsigned integer value to be converted.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToByte(System.Object)(Int64).

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToByte(int) Method

public static byte ToByte(int value);

Summary

Converts a Int32 to a Byte .

Parameters

value
The 32-bit signed integer value to be converted.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue or less than System.Byte.MinValue.

See Also

System.Convert Class, System Namespace

Convert.ToByte(ushort) Method

public static byte ToByte(ushort value);

Summary

Converts a UInt16 to a Byte .

Parameters

value
The 16-bit unsigned integer value to be converted.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToByte(System.Object)(Int32).

Example

The following example demonstrates converting UInt16 values to Byte values.

using System;
class ConvertByteTest {
    static public void Main() {
        ushort ushort0 = 0;
        ushort ushort1 = 32000;
        byte byte0 = Convert.ToByte(ushort0);
        Console.WriteLine("(ushort) {0} as byte = {1}",ushort0,byte0);
        byte byte1 = Convert.ToByte(ushort1); //Throws an exception.
        Console.WriteLine("(ushort) {0} as byte = {1}",ushort1,byte1);
    }
}
The output is

(ushort) 0 as byte = 0

Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte.

at Convert.ToByte(UInt16 value)

at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertUInt16.cs:line 8

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToByte(short) Method

public static byte ToByte(short value);

Summary

Converts a Int16 to a Byte .

Parameters

value
The 16-bit signed integer value to be converted.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Byte.MaxValue or less than System.Byte.MinValue.

See Also

System.Convert Class, System Namespace

Convert.ToByte(sbyte) Method

public static byte ToByte(sbyte value);

Summary

Converts a SByte to a Byte .

Parameters

value
The 8-bit signed integer to be converted.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is less than System.Byte.MinValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToByte(System.Object)(Int16).

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToByte(bool) Method

public static byte ToByte(bool value);

Summary

Converts a Boolean to a Byte .

Parameters

value
The Boolean value to be converted.

Return Value

If value equals true , returns 1; if value equals false , returns 0.

See Also

System.Convert Class, System Namespace

Convert.ToByte(byte) Method

public static byte ToByte(byte value);

Summary

Converts a Byte to a Byte .

Parameters

value
The Byte value to be converted.

Return Value

value is returned unchanged.

Description

[Note: This method is provided for completeness.]

See Also

System.Convert Class, System Namespace

Convert.ToByte(char) Method

public static byte ToByte(char value);

Summary

Converts a Char to a Byte .

Parameters

value
The Unicode character to be converted interpreted as an unsigned value.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
OverflowExceptionThe numeric value of value is greater than System.Byte.MaxValue.

Example

The following example demonstrates converting Char values to Byte values.

using System;
class ConvertByteTest {
    static public void Main() {
        char char0 = '0';
        char char1 = '1';
        char char2 = 'a'; 
        byte byte0 = Convert.ToByte(char0);
        byte byte1 = Convert.ToByte(char1);
        byte byte2 = Convert.ToByte(char2);
        Console.WriteLine("(char) {0} as byte = {1}",char0,byte0);
        Console.WriteLine("(char) {0} as byte = {1}",char1,byte1);
        Console.WriteLine("(char) {0} as byte = {1}",char2,byte2);
    }
}
The output is

(char) 0 as byte = 48

(char) 1 as byte = 49

(char) a as byte = 97

See Also

System.Convert Class, System Namespace

Convert.ToByte(System.String, System.IFormatProvider) Method

public static byte ToByte(string value, IFormatProvider provider);

Summary

Converts a String to a Byte .

Parameters

value
The String to be converted. The string is in the System.Globalization.NumberStyles.Integer style.
provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information.

Return Value

value as a Byte.

Exceptions

Exception TypeCondition
ArgumentNullExceptionvalue is a null reference.
FormatExceptionvalue does not consist of an optional sign followed by one or more digits (zero through nine).
OverflowExceptionThe numeric value of value is greater than System.Byte.MaxValue or less than System.Byte.MinValue.

Description

This method parses value using the information in the NumberFormatInfo instance supplied by provider. If provider is null or if a NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture.

See Also

System.Convert Class, System Namespace

Convert.ToChar(System.String) Method

public static char ToChar(string value);

Summary

Converts a String to a Char .

Parameters

value
The String to be converted. The String is required to contain a single character.

Return Value

value as a Char.

Exceptions

Exception TypeCondition
FormatExceptionvalue does not contain exactly one character.

See Also

System.Convert Class, System Namespace

Convert.ToChar(ulong) Method

public static char ToChar(ulong value);

Summary

Converts a UInt64 to a Char .

Parameters

value
The 64-bit unsigned integer value to be converted.

Return Value

value as a Char.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Char.MaxValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToChar(System.Object)(Int64).

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToChar(long) Method

public static char ToChar(long value);

Summary

Converts a Int64 to a Char .

Parameters

value
The 64-bit signed integer value to be converted.

Return Value

value as a Char.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Char.MaxValue or less than System.Char.MinValue.

See Also

System.Convert Class, System Namespace

Convert.ToChar(uint) Method

public static char ToChar(uint value);

Summary

Converts a UInt32 to a Char .

Parameters

value
The 32-bit unsigned integer value to be converted.

Return Value

value as a Char.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Char.MaxValue.

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToChar(int) Method

public static char ToChar(int value);

Summary

Converts a Int32 to a Char .

Parameters

value
The 32-bit signed integer value to be converted.

Return Value

value as a Char.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is greater than System.Char.MaxValue or less than System.Char.MinValue.

See Also

System.Convert Class, System Namespace

Convert.ToChar(ushort) Method

public static char ToChar(ushort value);

Summary

Converts a UInt16 to a Char .

Parameters

value
The 16-bit unsigned integer value to be converted.

Return Value

value as a Char.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToChar(System.Object)(Int32).

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToChar(short) Method

public static char ToChar(short value);

Summary

Converts a Int16 to a Char .

Parameters

value
The 16-bit signed integer value to be converted.

Return Value

value as a Char.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is less than System.Char.MinValue.

See Also

System.Convert Class, System Namespace

Convert.ToChar(byte) Method

public static char ToChar(byte value);

Summary

Converts a Byte to a Char .

Parameters

value
The Byte value to be converted.

Return Value

value as a Char.

See Also

System.Convert Class, System Namespace

Convert.ToChar(sbyte) Method

public static char ToChar(sbyte value);

Summary

Converts a SByte to a Char .

Parameters

value
The SByte value to be converted.

Return Value

value as a Char.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is less than System.Char.MinValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToChar(System.Object)(Int16).

Attributes

CLSCompliantAttribute(false)

See Also

System.Convert Class, System Namespace

Convert.ToChar(char) Method

public static char ToChar(char value);

Summary

Converts a Char to a Char .

Parameters

value
The Unicode character to be converted.

Return Value

value is returned unchanged.

Description

[Note: This method is provided for completeness.]

See Also

System.Convert Class, System Namespace

Convert.ToDateTime(System.DateTime) Method

public static DateTime ToDateTime(DateTime value);

Summary

Converts a DateTime to a DateTime .

Parameters

value
The DateTime to be converted.

Return Value

value is returned unchanged.

Description

[Note: This method is provided for completeness.]

See Also

System.Convert Class, System Namespace

Convert.ToDateTime(System.String) Method

public static DateTime ToDateTime(string value);

Summary

Converts a String to a DateTime structure.

Parameters

value
The String to be converted. The string is in a form allowed by the System.DateTime.Parse(System.String)(String) method.

Return Value

value as a DateTime.

Exceptions

Exception TypeCondition
ArgumentExceptionvalue is a null reference.
FormatExceptionvalue cannot be converted to a DateTime .

Description

This method parses value using the information in a DateTimeFormatInfo instance initialized for the current system culture.

See Also

System.Convert Class, System Namespace

Convert.ToDateTime(System.String, System.IFormatProvider) Method

public static DateTime ToDateTime(string value, IFormatProvider provider);

Summary

Converts a String to a DateTime structure.

Parameters

value
The String to be converted.
provider
A IFormatProvider that supplies a DateTimeFormatInfo containing culture-specific formatting information.

Return Value

value as a DateTime.

Exceptions

Exception TypeCondition
ArgumentExceptionvalue is a null reference.
FormatExceptionvalue cannot be converted to a DateTime .

Description

This method parses value using the information in the DateTimeFormatInfo instance supplied by provider. If provider is null or if a DateTimeFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture.

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(bool) Method

public static decimal ToDecimal(bool value);

Summary

Converts a Boolean to a Decimal .

Parameters

value
The Boolean value to be converted.

Return Value

If value is true returns 1; if value is false returns 0.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(System.Decimal) Method

public static decimal ToDecimal(decimal value);

Summary

Converts a Decimal to a Decimal .

Parameters

value
The Decimal value to be converted.

Return Value

value is returned unchanged.

Description

[Note: This method is provided for completeness.]

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(System.String, System.IFormatProvider) Method

public static decimal ToDecimal(string value, IFormatProvider provider);

Summary

Converts a String to a Decimal .

Parameters

value
The String to be converted. The string is in the System.Globalization.NumberStyles.Number style.
provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information.

Return Value

value as a Decimal.

Exceptions

Exception TypeCondition
ArgumentExceptionvalue is a null reference.
FormatExceptionvalue cannot be converted to a numeric value.
OverflowExceptionThe numeric value of value is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

Description

This method parses value using the information in the NumberFormatInfo instance supplied by provider. If provider is null or if a NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(System.String) Method

public static decimal ToDecimal(string value);

Summary

Converts a String to a Decimal .

Parameters

value
The String to be converted. The string is in the System.Globalization.NumberStyles.Number style.

Return Value

value as a Decimal.

Exceptions

Exception TypeCondition
ArgumentExceptionvalue is a null reference.
FormatExceptionvalue cannot be converted to a numeric value.
OverflowExceptionThe numeric value of value is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

Description

This method parses value using the information in a NumberFormatInfo instance initialized for the current system culture.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(double) Method

public static decimal ToDecimal(double value);

Summary

Converts a Double to a Decimal .

Parameters

value
The Double value to be converted.

Return Value

value as a Decimal. The Decimal contains 15 significant digits and is rounded using banker's rounding.

Exceptions

Exception TypeCondition
OverflowExceptionThe numeric value of value is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(float) Method

public static decimal ToDecimal(float value);

Summary

Converts a Single to a Decimal .

Parameters

value
The Single value to be converted.

Return Value

value as a Decimal. The Decimal contains 7 significant digits and is rounded using banker's rounding.

Exceptions

Exception TypeCondition
OverflowExceptionThe numeric value of value is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(ulong) Method

public static decimal ToDecimal(ulong value);

Summary

Converts a UInt64 to a Decimal .

Parameters

value
The 64-bit unsigned integer value to be converted.

Return Value

value as a Decimal.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(Decimal).

Attributes

CLSCompliantAttribute(false)

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(long) Method

public static decimal ToDecimal(long value);

Summary

Converts a Int64 to a Decimal .

Parameters

value
The 64-bit signed integer value to be converted.

Return Value

value as a Decimal.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(uint) Method

public static decimal ToDecimal(uint value);

Summary

Converts a UInt32 to a Decimal .

Parameters

value
The 32-bit unsigned integer value to be converted.

Return Value

value as a Decimal.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(Int64).

Attributes

CLSCompliantAttribute(false)

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(int) Method

public static decimal ToDecimal(int value);

Summary

Converts a Int32 to a Decimal .

Parameters

value
The 32-bit signed integer value to be converted.

Return Value

value as a Decimal.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(ushort) Method

public static decimal ToDecimal(ushort value);

Summary

Converts a UInt16 to a Decimal .

Parameters

value
The 16-bit unsigned integer value to be converted.

Return Value

value as a Decimal.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(Int32).

Attributes

CLSCompliantAttribute(false)

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(short) Method

public static decimal ToDecimal(short value);

Summary

Converts a Int16 to a Decimal .

Parameters

value
The 16-bit signed integer value to be converted.

Return Value

value as a Decimal.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(byte) Method

public static decimal ToDecimal(byte value);

Summary

Converts a Byte to a Decimal .

Parameters

value
The Byte value to be converted.

Return Value

value as a Decimal.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDecimal(sbyte) Method

public static decimal ToDecimal(sbyte value);

Summary

Converts a SByte to a Decimal .

Parameters

value
The SByte value to be converted.

Return Value

value as a Decimal.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(Int16).

Attributes

CLSCompliantAttribute(false)

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(double) Method

public static double ToDouble(double value);

Summary

Converts a Double to a Double .

Parameters

value
The Double value to be converted.

Return Value

value is returned unchanged.

Description

[Note: This method is provided for completeness.]

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(float) Method

public static double ToDouble(float value);

Summary

Converts a Single to a Double .

Parameters

value
The Single value to be converted.

Return Value

value as a Double.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(ulong) Method

public static double ToDouble(ulong value);

Summary

Converts a UInt64 to a Double .

Parameters

value
The 64-bit unsigned integer value to be converted.

Return Value

value as a Double.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDouble(System.Object)(Decimal).

Attributes

CLSCompliantAttribute(false)

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(long) Method

public static double ToDouble(long value);

Summary

Converts a Int64 to a Double .

Parameters

value
The 64-bit signed integer value to be converted.

Return Value

value as a Double.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(uint) Method

public static double ToDouble(uint value);

Summary

Converts a UInt32 to a Double .

Parameters

value
The 32-bit unsigned integer value to be converted.

Return Value

value as a Double.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDouble(System.Object)(Int64).

Attributes

CLSCompliantAttribute(false)

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(int) Method

public static double ToDouble(int value);

Summary

Converts a Int32 to a Double .

Parameters

value
The 32-bit signed integer value to be converted.

Return Value

value as a Double.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(ushort) Method

public static double ToDouble(ushort value);

Summary

Converts a UInt16 to a Double .

Parameters

value
The 16-bit unsigned integer value to be converted.

Return Value

value as a Double.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDouble(System.Object)(Int32).

Attributes

CLSCompliantAttribute(false)

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(short) Method

public static double ToDouble(short value);

Summary

Converts a Int16 to a Double .

Parameters

value
The 16-bit signed integer value to be converted.

Return Value

value as a Double.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(byte) Method

public static double ToDouble(byte value);

Summary

Converts a Byte to a Double .

Parameters

value
The Byte value to be converted.

Return Value

value as a Double.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(sbyte) Method

public static double ToDouble(sbyte value);

Summary

Converts a SByte to a Double .

Parameters

value
The SByte value to be converted.

Return Value

value as a Double.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDouble(System.Object)(Int16).

Attributes

CLSCompliantAttribute(false)

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(bool) Method

public static double ToDouble(bool value);

Summary

Converts a Boolean to a Double .

Parameters

value
The Boolean value to be converted.

Return Value

If value is true returns 1; if value is false returns 0.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(System.Decimal) Method

public static double ToDouble(decimal value);

Summary

Converts a Decimal to a Double .

Parameters

value
The Decimal value to be converted.

Return Value

value as a Double. value is rounded using banker's rounding.

Library

ExtendedNumerics

See Also

System.Convert Class, System Namespace

Convert.ToDouble(System.String) Method

public static double ToDouble(string value);

Summary

Converts a String to a Double .

Parameters

value
The String to be converted. The string is in the System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.AllowThousands style.

Return Value

value as a Double.

Exceptions

Exception TypeCondition
ArgumentNullExceptionvalue is a null reference.
FormatExceptionvalue cannot be converted to a numeric value.
OverflowExceptionThe numeric value of value is greater than System.Double.MaxValue or less than System.Double.MinValue.

Description

This method parses value using the inf