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
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
xis declared asdecimalbut the compiler has determined that the expression is of typedouble(and there is no implicit conversion fromdoubletodecimal), 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.)