Deferred Overload Resolution
In the preceding example, things are getting more interesting at runtime. As you will see later, a call site object is hiding behind the compiled code for the Math.Max call. Now it’s totally possible this code path gets hit multiple times, with different runtime types for a. One time, a may happen to be an Int32, so Math.Max really has two Int32 inputs. The runtime magic of dynamic will figure out the best overload is Math.Max(int, int) and will cause the call to be dispatched to that target method.
When another trip through the code is made with the runtime type of a being an Int64, the call site is now faced with an Int32 and an Int64. Again, in concert with the runtime binder, it will figure out the best overload ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access