how does C# search for best match overloaded method
<p>I got several questions about calling overloaded(or maybe I should call them hidden) methods in C#. Suppose I have classes as following:</p>

<pre><code>class ParaA {}
class ParaB : ParaA {}
class ParaC : ParaB {}

class TheBaseClass 
{
   public void DoJob (ParaA a){Console.WriteLine ("DoJob in TheBaseClass is being invoked");}

}

class TheDerivedClass : TheBaseClass 
{
  public void DoJob (ParaB b){Console.WriteLine ("DoJob in TheDerivedClass is being invoked");}
}

class Test
{
  //Case 1: which version of DoJob() is being called?
  TheDerivedClass aInstance= new TheDerivedClass ();
  aInstance.DoJob(new ParaA ());

  //Case 2: which version of DoJob() is being called?
  TheBaseClass aInstance= new TheDerivedClass ();
  aInstance.DoJob(new ParaA ());

  //Case 3: which version of DoJob() is being called?
  TheBaseClass aInstance= new TheDerivedClass ();
  aInstance.DoJob(new ParaB ());

  //Case 4: which version of DoJob() is being called?
  TheBaseClass aInstance= new TheDerivedClass ();
  aInstance.DoJob(new ParaC ());

}
</code></pre>

<p>I hope that I have made myself clear about what I am trying to do. I want to know how will C# search for the 'matched' version of method to invoke, when the parameters provided by the invoker do not perfectly match any signature but are compatible with some signatures. It makes me even more confused when methods are not just overloaded within a class, but also hidden, or overrided, or overloaded by derived classes. The example above does not cover every possible scenario. Is there any term for this?</p>

<p>Thank you guys in advance!</p>

<p>Matthew</p>
