Interesting behaviour of type “decimal” in C#

前端 未结 5 1109
遇见更好的自我
遇见更好的自我 2021-02-12 13:34

If we declare padding as const decimal, the padding is not working.

mymoney = 1.2 and your money = 1.20, how can this behavior be explained?

class Progra         


        
5条回答
  •  渐次进展
    2021-02-12 14:04

    If I'm not mistaken the complier isn't doing the addition with the constant decimal because it is zero.

    Will post proof shortly.

    Proof shown by Jon Skeet answer above.

提交回复
热议问题