Modifying parameter values before sending to Base constructor

前端 未结 7 515
借酒劲吻你
借酒劲吻你 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:00

    I expect you could call static methods in the parameter list of the base class constructor.

    public class DerivedClass : BaseClass
    {
        public DerivedClass(int i)
            : base(ChooseInputType(i))
        {
        }
    
        private static InputType ChooseInputType(int i)
        {
            // Logic
            return InputType.Number;
        }
    }
    

提交回复
热议问题