title: Why can't an anonymous method be assigned to var?
body: <p>I have the following code:</p>
  
  <pre><code>Func&lt;string, bool&gt; comparer = delegate(string value) {
      return value != "0";
  };
  </code></pre>
  
  <p>However, the following does not compile:</p>
  
  <pre><code>var comparer = delegate(string value) {
      return value != "0";
  };
  </code></pre>
  
  <p>Why can't the compiler figure out it is a <code>Func&lt;string, bool&gt;</code>? It takes one string parameter, and returns a boolean. Instead, it gives me the error:</p>
  
  <blockquote>
    <p>Cannot assign anonymous method to an
    implicitly-typed local variable.</p>
  </blockquote>
  
  <p>I have one guess and that is <em>if the var version compiled</em>, it would lack consistency if I had the following:</p>
  
  <pre><code>var comparer = delegate(string arg1, string arg2, string arg3, string arg4, string arg5) {
      return false;
  };
  </code></pre>
  
  <p>The above wouldn't make sense since Func&lt;> allows only up to 4 arguments (in .NET 3.5, which is what I am using). Perhaps someone could clarify the problem. Thanks.</p>