Why do I need an intermediate conversion to go from struct to decimal, but not struct to int?
Posted
by Jesse McGrew
on Stack Overflow
See other posts from Stack Overflow
or by Jesse McGrew
Published on 2010-05-10T22:11:10Z
Indexed on
2010/05/10
22:34 UTC
Read the original article
Hit count: 234
I have a struct like this, with an explicit conversion to float:
struct TwFix32
{
public static explicit operator float(TwFix32 x) { ... }
}
I can convert a TwFix32 to int with a single explicit cast: (int)fix32
But to convert it to decimal, I have to use two casts: (decimal)(float)fix32
There is no implicit conversion from float to either int or decimal. Why does the compiler let me omit the intermediate cast to float when I'm going to int, but not when I'm going to decimal?
© Stack Overflow or respective owner