why is this behavior?
It's unclear what you mean by “like this,” so first let me characterize the behavior correctly. The behavior you experience is: for the purpose of overload resolution, the applicable candidate method on the derived type is always better than the applicable candidate method on the base type. Moreover, a virtual method is considered as a method of a type that declares it, and not a type that overrides it.
It’s also not clear what you mean by “why”? “Why” questions are hard to answer; in a sense, the question already answered: why does the compiler demonstrate this behavior? Because this is a consequence of the above rules for breaking permission congestion. But then you can say that the question was being asked; the question now is "so why is the specification written that way?"
The specification was written that way because it reduces the problem of a fragile base class. The problem with a fragile base class is when you have two commands, one of which is working on the base class and one is working on the derived class. If the team working on the base class introduces a new method, then this should not change the behavior of code using the derived class. If so, then changing the base class is “broken” by the derived class. C # was carefully designed to troubleshoot a fragile base class.
Even getting out of the problem of a fragile base class, it makes sense to determine the priority of a method on a derived class. Derived class developers have more information than base class developers. They know that they have a banana in their hand; base class developers only know that they have Fruit. The challenge should go according to a method written by developers who had more information when possible.
Then you could say "well, I asked the question again, now I want to know why it is important to mitigate the problem of a fragile base class." Instead of continuing this endless regression, I will just leave it; if you want to know more, ask a less vague question.
If you are interested in mitigating the failure of a fragile base class, consider reading my long series of articles on it .
what is the difference between the functions
The difference is that one potential candidate is in its expanded form or in its normal form, while the other has only one candidate candidate form.
source share