C# casting int to float throwing exception (in runtime) -


this throws exception source can't casted destination:

int = 1; object b = (object)a; float c = (float)b; // exception here 

why?

you can cast boxed structs exact type, you'll need cast int first:

float c = (float)(int)b; 

however since there's implicit conversion float int, can do:

float c = (int)b; 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -