title: Dynamic type and static type C#
body: <p>I'm experimenting with C# and I built the following program (see below). </p>
  
  <p>I understand that the dynamic and static type of <code>first</code> is <code>C</code>. For <code>second</code> the dynamic type is also <code>C</code> but the static type is <code>A</code>. Now I wonder where this might come in handy?</p>
  
  <p>I noticed as well (obviously) that visual studio doesn't allow me to call <code>second.CallA()</code>.</p>
  
  <p>Now notice that when I call DoA() on all three types of static type, the dynamic type is <code>C</code>. As this is the case, why doesn't <code>this</code> point to that class? If i recall correct (I might be mistaking) in Java a <code>self.methodA()</code> would start looking up the inhertence tree from the caller instance. As it doesn't appear to be like that here. Can I create such behavior or is this a limitation of the language?</p>
  
  <pre><code>public class A
  {
      public void methodA()
      {
          Console.WriteLine("I am class A!");
      }
      public void DoA()
      {
          Console.Write("The type of this: " + this.GetType() + " - ");
          this.methodA();
      }
  }
  public class B : A
  {
      public void methodA()
      {
          Console.WriteLine("I am class B!");
      }
  }
  public class C : B
  {
      public void methodA()
      {
          Console.WriteLine("I am class C!");
      }
  }
  
  
  class Program
  {
      static void Main(string[] args)
      {
          C first = new C();
          A second = new C();
          dynamic third = new C();
  
          //Show the types of both
  
          Console.WriteLine(first.GetType() + "\n" + second.GetType() + "\n" + third.GetType());
          first.methodA();
          second.methodA();
          third.methodA();
  
          first.DoA();
          second.DoA();
          third.DoA();
  
  
  
          Console.ReadLine();
      }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>C
  C
  C
  I am class C!
  I am class A!
  I am class C!
  The type of this: C - I am class A!
  The type of this: C - I am class A!
  The type of this: C - I am class A!
  </code></pre>