Modifying parameter values before sending to Base constructor

前端 未结 7 513
借酒劲吻你
借酒劲吻你 2021-01-07 16:26

The title may be a bit ambiguous, but I couldn\'t think of a better way to word this.

I realize that I can not call a derived constructor prior to calling a base con

相关标签:
7条回答
  • 2021-01-07 17:11

    You can use a static method to compute a value to pass to the base constructor.

    public class DerivedClass :
        BaseClass
    {
        public
        DerivedClass(int i) :
            base(ComputedValue(i))
        {
        }
    
        public static InputType
        ComputedValue(int i)
        {
            return InputType.Number; // or any other computation you want here
        }
    }
    
    0 讨论(0)
提交回复
热议问题