Given,
Method overloading = compile time resolution.
Method overriding = run-time resolution.
How does CLR resolve the following method call (involving a dynamic type) ?
dynamic intValue = -10;
var result = Math.Abs(intValue);
Thanks for your interest.
The process of connecting names to what they are is called binding. Normal overload resolution is ‘early’ binding, because the exact meaning of the method name is determined early – at compile time.
When the compiler encounters a virtual method during overload resolution, it emits a virtual call. At runtime, this is routed to the correct method, possibly to an override.
When the compiler encounters a dynamic object, it emits code to perform ‘late’ binding, i.e. at runtime. Late binding is like overload resolution at runtime. The code looks at the argument, finds out its an integer, looks up the correct overload to call, and calls it.
Well, it actually does a bit more than that. It caches the result of the lookup and puts in a test so that the next time the code is run, it can go right to calling the correct method if the argument type is
int.This is still a simplification. In reality, several more optimizations may be done to gain optimal performance.
See this blog post for a more thorough explanation of exactly what would happen with your example.