次の方法で共有


When does the compiler dispatch a call dynamically?

There are 2 cases when a call will be dispatched dynamically:

  1. When the receiver of the call is statically typed as dynamic

        1: dynamic d = new MyClass();
        2: d.Foo();
    
  2. When any of the arguments to the call are statically typed as dynamic

        1: var o = new MyClass();
        2: dynamic d = 4;
        3: o.Bar(d);
    

By keeping the rules simple we hope to avoid cases where there is confusion about whether or not a call is dispatched dynamically.