title: Self-invoking anonymous functions
body: <p>In JavaScript, it's not uncommon to see self-invoking functions:</p>
  
  <pre><code>var i = (function(x) {
      return x;
  })(42);
  
  // i == 42
  </code></pre>
  
  <p>While I'm certainly not comparing the languages, I figured such a construct would be translatable to C#, provided a language version with support:</p>
  
  <pre><code>var i = (delegate(int x) {
      return x;
  })(42);
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>var i = ((x) =&gt; {
      return x;
  })(42);
  </code></pre>
  
  <p>Or even:</p>
  
  <pre><code>var i = (x =&gt; x)(42);
  </code></pre>
  
  <p>However, every version is in error:</p>
  
  <blockquote>
    <p>Method name expected</p>
  </blockquote>
  
  <p>Are self-invoking anonymous methods unsupported (<em>due either to explicit forbiddance, or the impossibility of type inference</em>), or is there an error in my attempts? </p>
  
  <p>I'm venturing a guess that because there was no method declaration (<em><code>Func&lt;T,T&gt;</code></em>) against which the types could be inferred, it can't sort out the implied types, figures I meant to call a declared method by name, and really goofed up the syntax.</p>
  
  <hr>
  
  <p><strong>Errata</strong></p>
  
  <p>Before this question is flooded with:</p>
  
  <pre><code>var i = new Func&lt;int, int&gt;(x =&gt; x)(42);
  </code></pre>
  
  <p>I should say that I was hoping to leverage type inference, but I suppose that may not be possible due to being <em>overly</em>-implicit.</p>
  
  <p>So, clarifying the question a bit; we know we can <code>var i = new Func&lt;int, int&gt;(x =&gt; x)(42);</code> but without creating an instance of, or casting to <code>Func</code>, is this possible?</p>
  
  <p><strong>Use-Case</strong></p>
  
  <p>For those curious (<em>or concerned</em>) the use case was something like this:</p>
  
  <pre><code>var o = new {
      PropertyA = () =&gt; {
          // value computation
      }(),
      PropertyB = () =&gt; {
          // value computation
      }(),
  };
  </code></pre>