我想将可空十进制转换为原始十进制.这该怎么做.我做了一些谷歌搜索,发现System.ComponentModel.NullableConverter作为解决方案之一.但我无法弄清楚如何使用它.
decimal? offenceAmount = 23;
decimal primitive;
primitive=offenceAmount; //
Run Code Online (Sandbox Code Playgroud)
请帮忙.
你可以做:
if (offenceAmount.HasValue) {
primitive = offenceAmount.Value;
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您希望结果默认为0:
primitive = offenceAmount.GetValueOrDefault();
Run Code Online (Sandbox Code Playgroud)
或者上面的快捷方式:
primitive = offenseAmount ?? 0;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
385 次 |
| 最近记录: |