Equivalent in C# of "Block values" in other languages
<p>In some languages, almost everything can be used as a value. For example, some languages let you treat a block of code as a unit which can return a value.</p>

<p>In Scheme, a block of code wrapped in a <code>let</code> can return a value:</p>

<pre><code>(define val
  (let ()
    (define a 10)
    (define b 20)
    (define c (+ a b))
    c))
</code></pre>

<p>Perl 5 also supports blocks as values:</p>

<pre><code>my $val = do
{
    my $a = 100;
    my $b = 200;
    my $c = $a + $b;
    $c;
};
</code></pre>

<p>The closest approximation to block values I could come up with in C# was to use a lambda that is cast and immediately called:</p>

<pre><code>var val = ((Func&lt;int&gt;)(() =&gt;
{
    var a = 10;
    var b = 20;
    var c = a + b;
    return c;
}))();
</code></pre>

<p>That's not too bad and is in fact exactly what is happening semantically with Scheme; the <code>let</code> is transformed to a <code>lambda</code> which is applied. It's at this point that I wouldn't mind macros in C# to clean up the syntactic clutter.</p>

<p>Is there an another way to get "block values" in C#?</p>
