title: Why can't the compiler figure out that this lambda is a Delegate?
body: <p>Consider this tiny program.</p>
  
  <pre><code>public class Program
  {
      public static void Main()
      {
          // the first path compiles
          RunAction(() =&gt; { });
  
          // the second path does not compile
          RunDelegate(() =&gt; {});
      }
  
      private static void RunAction(Action run) =&gt; RunDelegate(run);
      private static void RunDelegate(Delegate run) { }
  }
  </code></pre>
  
  <p>The first path compiles and implies that </p>
  
  <ol>
  <li>the <code>() =&gt; {}</code> lambda is an <code>Action</code>, </li>
  <li>the <code>Action</code> is a <code>Delegate</code>, and </li>
  <li>therefor that the <code>() =&gt; {}</code> lambda is a <code>Delegate</code>.</li>
  </ol>
  
  <p><strong>Why does the second path not compile?</strong></p>
  
  <p>Usually the compiler is able to make the leap between steps (1) and (3). Here is an example of how the compiler usually handles this kind of nested is-a relationships.  </p>
  
  <pre><code>public class Program2
  {
      public static void Main()
      {
          // both of these comple
          AcceptPerson(new Programmer());
          AcceptAnimal(new Programmer());
      }
  
      private static void AcceptPerson(Person p) =&gt; AcceptAnimal(p);
      private static void AcceptAnimal(Animal a) { }
  }
  
  public class Programmer : Person { }
  public class Person : Animal { }
  public class Animal { }
  </code></pre>