title: How does compiler optimize virtual methods implemented by a sealed class
body: <p>I'm wondering how the following code is optimized. Specifically concerning virtual and direct calls. I have commented on how I think everything is optimized but those are just guesses.</p>
  
  <pre><code>public abstract class Super
  {
      public abstract void Foo();
  
      public void FooUser()
      {
          Foo();
      }
  }
  
  public class Child1 : Super
  {
      public override void Foo()
      {
          //doSomething
      }
  }
  
  public class SealedChild : Super
  {
      public override void Foo()
      {
          //doSomething
      }
  }
  
  class Program
  {
      void main()
      {
          Child1 child1 = new Child1();
          child1.Foo(); //Virtual call?
          child1.FooUser(); //Direct call and then a virtual call. 
  
          SealedChild sealedChild = new SealedChild();
          sealedChild.Foo(); //Direct call?
          sealedChild.FooUser(); 
          /* Two options: either a direct call &amp; then a virtual call
           * Or: direct call with a parameter that has a function pointer to Foo, and then a direct call to foo.
           */
  
          Super super = child1;
          super.Foo(); //Virtual call.
          super.FooUser(); //Virtual call then direct call.
      }
  }
  </code></pre>