C# Generics : how to use x.MaxValue / x.MinValue (int, float, double) in a generic class

前端 未结 4 1875
天涯浪人
天涯浪人 2021-01-05 03:59

I\'m using the WPF Extended Toolkit ( http://wpftoolkit.codeplex.com/ ).

It has a nice NumericUpDown control that I\'d like to use, but internally it uses doubles -

4条回答
  •  无人及你
    2021-01-05 04:22

    The OP made this comment on another answer:

    I want to use these controls in my XAML. My idea was to create a generic version, and then create empty classes like NumericUpDownInt : GNumericUpDown { } Would that be the way to go, or is there a better/cleaner way to your knowledge

    If you're going to go that route, then just pass the min and max directly:

    class abstract GenericNumericUpDown
    {
        public GenericNumericUpDown(T min, T max) { ... }
    }
    
    class NumericUpDownInt : GenericNumericUpDown
    {
        public NumericUpDownInt() : base(int.MinValue, int.MaxValue) { ... }
    }
    
    class NumericUpDownFloat : GenericNumericUpDown
    {
        public NumericUpDownFloat() : base(float.MinValue, float.MaxValue) { ... }
    }
    
    class NumericUpDownDouble : GenericNumericUpDown
    {
        public NumericUpDownDouble() : base(double.MinValue, double.MaxValue) { ... }
    }
    

提交回复
热议问题