我已经为NumericUpDown控件创建了一个包装器。
这个包装器是通用的,可以支持int?和double?。
我想编写一个方法,实现以下功能。
当然,十进制和双精度浮点型之间没有转换方式?或者整型和双精度浮点型之间也没有?所以我需要使用一定的转换方法。我想要避免使用switch或if表达式。
你会怎么做?
为了阐明我的问题,我提供了更多的代码...
我想编写一个方法,实现以下功能。
public partial class NullableNumericUpDown<T> : UserControl where T : struct
{
private NumbericUpDown numericUpDown;
private T? Getvalue()
{
T? value = numericUpDown.Value as T?; // <-- this is null :) thus my question
return value;
}}
当然,十进制和双精度浮点型之间没有转换方式?或者整型和双精度浮点型之间也没有?所以我需要使用一定的转换方法。我想要避免使用switch或if表达式。
你会怎么做?
为了阐明我的问题,我提供了更多的代码...