Modifying parameter values before sending to Base constructor

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

    You say

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

    But then you show this code

    public DerivedClass(int i)
        : base(value)
    {
        // Is it possible to set "value" here?
        // Logic
    }
    

    When that code block is entered you base class constructor has already run. You can however modify the value in an expression before passing it to the base constructor (with some obvious constraints). However, you will not have access to 'value' unless it is an input to the constructor.

提交回复
热议问题