Why do I need an intermediate conversion to go from struct to decimal, but not struct to int?
- by Jesse McGrew
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?