Casting to double
-
I encountered the following problem and I am confused now. I'm sure that cunning foxes are around to help me. Take this code:
object o = new object(); o = 1; double dValue = (double) o;
The cast doesn't work and the error message comes up: An unhandled exception of type 'System.InvalidCastException' occurred. Thanks in advance! Chris -
I encountered the following problem and I am confused now. I'm sure that cunning foxes are around to help me. Take this code:
object o = new object(); o = 1; double dValue = (double) o;
The cast doesn't work and the error message comes up: An unhandled exception of type 'System.InvalidCastException' occurred. Thanks in advance! Chrisobject o = new object(); o = 1; double dValue = Convert.ToDouble(o); Live Life King Size Alomgir Miah
-
I encountered the following problem and I am confused now. I'm sure that cunning foxes are around to help me. Take this code:
object o = new object(); o = 1; double dValue = (double) o;
The cast doesn't work and the error message comes up: An unhandled exception of type 'System.InvalidCastException' occurred. Thanks in advance! ChrisYou are boxing an integer into an object. You can only unbox it as an integer:
(int)o
After you have unboxed the value, you can convert it to a double:double dValue = (double)(int)o;
If you want to store a double in the object, you have to specify that the value is a double:o = 1d;
--- b { font-weight: normal; } -
You are boxing an integer into an object. You can only unbox it as an integer:
(int)o
After you have unboxed the value, you can convert it to a double:double dValue = (double)(int)o;
If you want to store a double in the object, you have to specify that the value is a double:o = 1d;
--- b { font-weight: normal; }