I am just curious to know why do we need to append m or M for decimal type?
Documentation says there is no implicit conversion
I think the compiler has enough information because we declare Decimal
key word.
Can some one please explain why can not the compiler determine the value should be treated as decimal but not double.
If you have a statement like this
decimal x = 5.6;
the compiler first looks only at the right-hand side of the assignment (5.6
), determines its type (double
) and then checks if the result can be assigned to the variable on the left-hand side (x
).
Since x
is declared as decimal
but the compiler has determined that the expression is of type double
(and there is no implicit conversion from double
to decimal
), the assignment is invalid.
(The only exception to this rule is assigning a lambda expression to a delegate variable. In this case, the compiler indeed uses the information at the left-hand side to determine the type of the right-hand side.)
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