我怎么能转换成十进制?为十进制 [英] How can I convert decimal? to decimal

查看:160
本文介绍了我怎么能转换成十进制?为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能是它是一个简单的问题,但我尝试所有转换方法!它仍然有错误! 你会帮我吗?

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

推荐答案

有很多的选择......

There's plenty of options...

decimal? x = ...

decimal a = (decimal)x; // works; throws if x was null
decimal b = x ?? 123M; // works; defaults to 123M if x was null
decimal c = x.Value; // works; throws if x was null
decimal d = x.GetValueOrDefault(); // works; defaults to 0M if x was null
decimal e = x.GetValueOrDefault(123M); // works; defaults to 123M if x was null
object o = x; // this is not the ideal usage!
decimal f = (decimal)o; // works; throws if x was null; boxes otherwise

这篇关于我怎么能转换成十进制?为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆