Cast object to decimal? (nullable decimal)

后端 未结 5 1125
天涯浪人
天涯浪人 2020-12-02 22:54

If have this in the setter of a property:

decimal? temp = value as decimal?;

value = \"90\"

But after the cast, temp is nul

5条回答
  •  佛祖请我去吃肉
    2020-12-02 23:22

    Surprisingly, but good old System.Convert.ToDecimal(myNullableDoubleBoxedInObject) works perfectly:

    decimal? myNullableDecimal = 0.15m;
    object myNullableDoubleBoxedInObject = myNullableDouble ;
    decimal myDecimal = System.Convert.ToDouble(myNullableDoubleBoxedInObject);
    

提交回复
热议问题