From the msdn page :
public static double ToDouble( char value )
Parameters
value
Type: System.Char The Unicode character to convert.Return Value
Type: System.Double This conversion is not supported. No value is returned.
If it is not supported, why is it implemented in the first place ?
To convert a specified value to a double-precision floating-point number, use Convert. ToDouble() method. long[] val = { 340, -200}; Now convert it to Double.
String value can be converted to double using Convert. ToDouble() or Double. Parse() method. These methods take string representation of a number as input and return its equivalent double-precision floating-point number.
You can also convert a Decimal to a Double value by using the Explicit assignment operator. Because the conversion can entail a loss of precision, you must use a casting operator in C# or a conversion function in Visual Basic.
} // Int to double conversion cannot overflow. doubleVal = System.Convert.ToDouble (intVal); System.Console.WriteLine (" {0} as a double is: {1}", intVal, doubleVal); } Public Sub ConvertDoubleInt (ByVal doubleVal As Double) Dim intVal As Integer = 0 ' Double to Integer conversion can overflow.
it is also possible, that in some scenarios you are trying to convert a char array eg.: Sign in to answer this question. Unable to complete the action because of changes made to the page.
// Converted the Int64 value '9223372036854775807' to the Double value 9.22337203685478E+18.
It is not the only one. Convert.ToBoolean(char), ToDateTime, ToDecimal and ToSingle are also not supported, they all throw InvalidCastException like ToDouble does.
This is just .NET design trying to keep you out of trouble. Converting a char to an integral type is reasonable, you can look at the Unicode mapping tables and count the codepoints. But what would a conversion to Boolean mean? What Unicode code point is True? ToDateTime requires no explanation. How could a character ever be a fractional value? There are no half or quarter codepoints.
You can make it work, convert to Int32 first and then convert to Double. But by all means, check your code and make sure that it is a senseful thing to do. The .NET designers thought it wasn't. They were right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With