title: Overloaded Method..why is base class given precedence?
body: <p>In the following code, i have an overloaded method, one that takes a parameter of type ClazzA and the other of type ClazzB.  In the code shown, the first GetDescription method (the one that takes ClazzA as a parameter) is called.  I think i understand why.<br>
  My question is..is there an elegant way of having the method that takes clazzB called first if the underlying object is of type classB (without having to inspect each object and casting it to clazzB)?</p>
  
  <pre><code>public class ClazzA
  {
      public virtual string Descr { get { return "A"; } }
  }
  
  public class ClazzB : ClazzA
  {
      public override string Descr { get { return "B"; } }
  }
  
  public static class test
  {
      public static void Main()
      {
          ClazzA test = new ClazzB();
          GetDecription(test);
      }
  
      public static void GetDecription(ClazzA someClazz)
      {
          Debug.WriteLine("I am here");
      }
  
      public static void GetDecription(ClazzB someClazz)
      {
          Debug.WriteLine("I want to be here");
      }
  }
  </code></pre>
  
  <p>Output: "I am here"</p>
  
  <p>I really want the 2nd method to be called since 'test' is of type ClassB.  Curerently the only two solutions i have is:</p>
  
  <ol>
  <li><p>if (test is ClazzB) 
        return GetDescription( (ClazzB) test ); </p></li>
  </ol>
  
  <p>or</p>
  
  <ol>
  <li>In ClassA do pretty much the same thing...check the type and delegate to the 2nd method</li>
  </ol>
  
  <p>Both of these require inspection of the object to determine its type</p>