Explicit interface implementation cannot be virtual

后端 未结 5 1739
遥遥无期
遥遥无期 2021-02-05 13:20

For the record, I\'ve already seen this connect item but I can\'t really understand what would be the problem in supporting this.

Say I have the following code:

5条回答
  •  名媛妹妹
    2021-02-05 13:38

    however this way I've really no indication at all that I'm overriding something

    Well, you do, sort of - you have the fact that it's clearly an explicit interface implementation. That shows it's providing polymorphic behaviour for that method call which is specified on an interface... why does it matter whether the base class also implemented the interface? What difference will it make to you when you read the code?

    To me, the main benefit of stating override is to make sure I've really got the right signature - that it matches the thing I'm trying to override. You've already got that benefit with explicit interface implementation, as if you give a non-existent method or the wrong parameters etc, the compiler will already complain.

    I can sort of see your point, but I've never found it to be an actual problem.

提交回复
热议问题