How can I convert decimal? to decimal

后端 未结 5 1018
-上瘾入骨i
-上瘾入骨i 2021-02-02 05:31

may be it is a simple question but I\'m try all of conversion method! and it still has error! would you help me?

decimal? (nullable decimal) to decimal

5条回答
  •  被撕碎了的回忆
    2021-02-02 06:07

    It depends what you want to do if the decimal? is null, since a decimal can't be null. If you want to default that to 0, you can use this code (using the null coalescing operator):

    decimal? nullabledecimal = 12;
    
    decimal myDecimal = nullabledecimal ?? 0;
    

提交回复
热议问题