One of the most interesting things with the dynamic keyword that you can do is implement a dual send. In OOP, a specific implementation of a virtual (or abstract) method is called at run time based on the runtime type of a single object, which is passed as this to a member function. This is called a single dispatch, since dispatch depends on the type of runtime of a single object. In double submission, it depends on the type of two objects.
Here is one example:
public abstract class Base {} public class D1 : Base {} public class D2 : Base {} public class D3 : Base {} public class Test { public static void Main(string[] args) { Base b1 = new D1(); Base b2 = new D2(); Method(b1,b2);
Output:
(D1,D2) (D2,D1)
That is, the actual method is selected at runtime based on the runtime type of two objects, as opposed to a single object.
Nawaz Nov 20 '11 at 17:45 2011-11-20 17:45
source share