Recently I have produced a code with strange behaviour in my real C# project. Look at this code:
There is nothing strange. The method
Mystery.Foo(int)is called repeatedly. Then I replaced hidding method
Mystery.Foo(int)by overriding method:
And the output is:
Hah! What is the matter? Let us go to explore IL code of method
ihas been boxed. Why? I would expect that the IL body of method
Mystery.Foo(int)will be the same in new and override declaration but it is different. It is very strange behaviour of compiler. What is your explanation?
Overridded method in my real project was the right one. In addition, I renamed the methods, because my colleagues could be confused like me.