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 ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.