<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx</link><description>&amp;lt;Edit: See the extended discussion at the end of which I conclude Anonymous methods are indeed lexical closures!!! &amp;gt; Anonymous methods in C# are just anonymous methods and do not represent true lexical closure . There are a lot of samples and code</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#482201</link><pubDate>Tue, 18 Oct 2005 14:50:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:482201</guid><dc:creator>Dan Muller</dc:creator><description>Actually, this demonstrates why C# _does_ have true lexical closure. In the first C# example, i has a single lexical binding during definition of all the functions, and they all share that one binding, so they all print its _current_ value.&lt;br&gt;&lt;br&gt;Similar Common Lisp code (using a list instead of an array) looks like this:&lt;br&gt;&lt;br&gt;(setq arr (loop for i upto 10 collect #'(lambda () (format t &amp;quot;~A &amp;quot; i))))&lt;br&gt;&lt;br&gt;(loop for val in arr (apply val))&lt;br&gt;&lt;br&gt;The output is:&lt;br&gt;11 11 11 11 11 11 11 11 11 11 11&lt;br&gt;&lt;br&gt;Note that in your examples, the Ruby example creates 11 functions, while the C# creates 10. This Lisp example creates 11.&lt;br&gt;&lt;br&gt;In your second C# example, j is introduced as a name binding in the loop body; thus a _different_ binding is seen by each created function. This is exactly as expected with lexical closure.&lt;br&gt;&lt;br&gt;Ruby has odd rules with respect to the lexical binding of names. Since i is not defined before the loop, the i in the loop acts like a _parameter_ to the loop body, which means that it is bound anew on each iteration. If you simply add the statement &amp;quot;i = 0&amp;quot; before the loop, i is now lexically bound _outside_ the loop, and you get results similar to the C# case (except you'll print tens instead of elevenses, due to the fencepost error in your examples).&lt;br&gt;&lt;br&gt;</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#482212</link><pubDate>Tue, 18 Oct 2005 16:01:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:482212</guid><dc:creator>Andreas</dc:creator><description>If you change funcGen to&lt;br&gt;&lt;br&gt;def funcGen(val)&lt;br&gt;  for i in 0..val&lt;br&gt;    $arr[i] = Proc.new {&lt;br&gt;      print i&lt;br&gt;      print ' '&lt;br&gt;    }&lt;br&gt;  end&lt;br&gt;end&lt;br&gt;&lt;br&gt;you will get the same behavior as in C#.</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#482266</link><pubDate>Tue, 18 Oct 2005 18:28:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:482266</guid><dc:creator>Wesner Moise</dc:creator><description>C# implements true closures...&lt;br&gt;&lt;br&gt;The ruby example that you showed does not demonstrate lexical closure, because i is being used as a parameter. The ruby is more analogous to calling the following C# function.&lt;br&gt;&lt;br&gt;public void UpTo(int start, int end, ToAction&amp;lt;int&amp;gt; func)&lt;br&gt;{&lt;br&gt;    for (int i=start; i&amp;lt;=end; i++)&lt;br&gt;        func(i);&lt;br&gt;}&lt;br&gt;&lt;br&gt;In this case, this makes it clear that i is a parameter to a function. &lt;br&gt;&lt;br&gt;</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#482364</link><pubDate>Tue, 18 Oct 2005 22:16:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:482364</guid><dc:creator>Gabe</dc:creator><description>I'm a bit confused... First you show an example of closures. Then a couple steps later you show an example of how to get the exact same result from C#, but conclude that C# doesn't have closures?&lt;br&gt;&lt;br&gt;Quite frankly, closures wouldn't be terribly useful if they could only capture the value of a variable at the time of its instantiation. You'd end up with an implementation of Java's inner classes.</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#482555</link><pubDate>Wed, 19 Oct 2005 09:58:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:482555</guid><dc:creator>abhinaba</dc:creator><description>To clarify Gabe, what I tried to show was that if C# did implement true closure then in either case the same result should have been obtained and tweaking to get the desired effect would have not been required.&lt;br&gt;&lt;br&gt;Definitions of Lexical closures seem to vary and so does the opinion on whether C# implements closure. To quote Brad Adams (&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/brada/archive/2004/08/03/207164.aspx"&gt;http://blogs.msdn.com/brada/archive/2004/08/03/207164.aspx&lt;/a&gt;) &amp;quot;Anonymous methods are not closures or completions. They are anonymous methods. They allow sharing of variables with the outer method (not copy in, or copy out, or copy in-out, or even by ref) &amp;quot;&lt;br&gt;&lt;br&gt;In one definition of closure from the C2 wiki is that &amp;quot;In proper closures, not just the value is kept, but a reference to the actual object passed in&amp;quot;. In this case C# does implement closure. &lt;br&gt;&lt;br&gt;Again in another definition &amp;quot;during the creation of the closure the lexical environment is captured&amp;quot;. In C# since changes made in child scope propagate to the parent scope and to all other closures it does not implement closure.&lt;br&gt;</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#482652</link><pubDate>Wed, 19 Oct 2005 18:25:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:482652</guid><dc:creator>Dan Muller</dc:creator><description>The discussions in that other blog are somewhat confused, and the&lt;br&gt;C2 page is not as clear as it could be.&lt;br&gt;&lt;br&gt;The context that code runs in consists of mappings of names to&lt;br&gt;things, most notably (in this case) to variables. A variable is&lt;br&gt;any location where you can store a value (a value, usually, an&lt;br&gt;object reference in C#). It is this name/variable (not&lt;br&gt;name/value) mapping that is at issue in closures.&lt;br&gt;&lt;br&gt;In a language with lexical scoping (which is to say, most&lt;br&gt;languages nowadays), the lexical enclosing scope of some code&lt;br&gt;determines the name/variable mappings. A local variable name&lt;br&gt;defined (or 'bound'. to use Lisp terminology) in a method will&lt;br&gt;refer to a different, unique variable each time the method is&lt;br&gt;called, even though it's the same name and the same code that&lt;br&gt;references it.&lt;br&gt;&lt;br&gt;When you create a closure, you're creating a function that&lt;br&gt;'closes over' its lexical environment as it exists when the&lt;br&gt;closure is created.  This means that the name/variable bindings&lt;br&gt;that are active _at the time the closure is created_ continue to&lt;br&gt;exist for that closure. If other closures are created (e.g. the&lt;br&gt;ten (or eleven) closures in your examples) in the same lexical&lt;br&gt;environment, they then share the same name/variable mappings. But&lt;br&gt;note that the same lexical scope, invoked multiple times, can&lt;br&gt;produce distinct bindings. Each such environment is a _distinct_&lt;br&gt;lexical environment.&lt;br&gt;&lt;br&gt;Even the definition of closure on&lt;br&gt;wikipedia (&lt;a rel="nofollow" target="_new" href="http://en.wikipedia.org/wiki/Lexical_closure"&gt;http://en.wikipedia.org/wiki/Lexical_closure&lt;/a&gt;) is a bit&lt;br&gt;weak because it talks about name/value mappings, not&lt;br&gt;name/variable mappings. But see the notes about 'delay&lt;br&gt;evaluation' and 'multiple functions'. (BTW, learning Lisp helped&lt;br&gt;me immensely in fine-tuning my understanding of environments,&lt;br&gt;bindings, the distinctions between variables and names, variable&lt;br&gt;lifetimes, and other fundamental programming language isssues.)&lt;br&gt;&lt;br&gt;To really appreciate this, you need examples that show the&lt;br&gt;mutability and shared nature of the variables from the lexical&lt;br&gt;environment, as well as how the variables are distinct when they&lt;br&gt;come from different invocations of the lexical&lt;br&gt;environment. Here's an example in Ruby.&lt;br&gt;&lt;br&gt;-----------------&lt;br&gt;$printers = Array.new&lt;br&gt;$setters = Array.new&lt;br&gt;&lt;br&gt;# Function funcGen creates two lexical closures each time it's called;&lt;br&gt;# one setter and one printer. These two functions share a&lt;br&gt;# lexically-scoped variable referred to by num that is unique to these&lt;br&gt;# two functions.&lt;br&gt;def funcGen()&lt;br&gt;  # We get a new binding of num to a unique variable each time we get&lt;br&gt;  # here.&lt;br&gt;  num = 0&lt;br&gt;  $printers.push(Proc.new {&lt;br&gt;		   print num&lt;br&gt;		   print ' '&lt;br&gt;		 })&lt;br&gt;  $setters.push(Proc.new {|new_num|&lt;br&gt;		  # Change the value of num.&lt;br&gt;		  num = new_num})&lt;br&gt;end&lt;br&gt;&lt;br&gt;# Generate ten setter/getter pairs.&lt;br&gt;0.upto(9) {&lt;br&gt;  funcGen()&lt;br&gt;}&lt;br&gt;&lt;br&gt;# Initially, all the printers will print zero.&lt;br&gt;$printers.each do |f|&lt;br&gt;  f.call&lt;br&gt;end&lt;br&gt;puts&lt;br&gt;&lt;br&gt;# Tell each setter to modify its shared variable.&lt;br&gt;0.upto(9) do |i|&lt;br&gt;  $setters[i].call(i+1)&lt;br&gt;end&lt;br&gt;&lt;br&gt;# Each printer should print a different value now.&lt;br&gt;$printers.each do |f|&lt;br&gt;  f.call&lt;br&gt;end&lt;br&gt;-----------------&lt;br&gt;&lt;br&gt;Here's similar code in lisp.&lt;br&gt;&lt;br&gt;-----------------&lt;br&gt;(defparameter setters nil)&lt;br&gt;(defparameter printers nil)&lt;br&gt;&lt;br&gt;(defun genFun ()&lt;br&gt;  (let ((num 0))&lt;br&gt;    (push #'(lambda (new_num) (setq num new_num)) setters)&lt;br&gt;    (push #'(lambda () (format t &amp;quot;~A &amp;quot; num)) printers)))&lt;br&gt;&lt;br&gt;; Generate ten setter/getter pairs.&lt;br&gt;(dotimes (i 10)&lt;br&gt;  (genFun))&lt;br&gt;&lt;br&gt;; Initially, all the printers will print zero.&lt;br&gt;(format t &amp;quot;~%&amp;quot;)&lt;br&gt;(loop for val in printers&lt;br&gt;   do (apply val nil))&lt;br&gt;&lt;br&gt;; Tell each setter to modify its shared variable.&lt;br&gt;(loop&lt;br&gt;   for val in setters&lt;br&gt;   for i upfrom 0&lt;br&gt;   do (apply val (+ i 1) nil))&lt;br&gt;&lt;br&gt;; Each printer should print a different value now.&lt;br&gt;(format t &amp;quot;~%&amp;quot;)&lt;br&gt;(loop for val in printers&lt;br&gt;     do (apply val nil))&lt;br&gt;-----------------&lt;br&gt;&lt;br&gt;Anyone care to try a C# version to test the closures there?&lt;br&gt;&lt;br&gt;</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#483228</link><pubDate>Fri, 21 Oct 2005 01:39:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:483228</guid><dc:creator>James Arendt</dc:creator><description>class Program&lt;br&gt;{&lt;br&gt;    delegate void Func();&lt;br&gt;    delegate void PrintersFunc();&lt;br&gt;    delegate void SettersFunc(int new_num);&lt;br&gt;&lt;br&gt;    static List&amp;lt;PrintersFunc&amp;gt; printers = new List&amp;lt;PrintersFunc&amp;gt;();&lt;br&gt;    static List&amp;lt;SettersFunc&amp;gt; setters = new List&amp;lt;SettersFunc&amp;gt;();&lt;br&gt;&lt;br&gt;    static void FuncGen()&lt;br&gt;    {&lt;br&gt;        int num = 0;&lt;br&gt;        printers.Add(delegate()&lt;br&gt;        {&lt;br&gt;            Console.Write(num);&lt;br&gt;            Console.Write(' ');&lt;br&gt;        });&lt;br&gt;&lt;br&gt;        setters.Add(delegate(int new_num)&lt;br&gt;        {&lt;br&gt;            num = new_num;&lt;br&gt;        });&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    static void Main(string[] args)&lt;br&gt;    {&lt;br&gt;        for (int i = 0; i &amp;lt; 10; i++)&lt;br&gt;        {&lt;br&gt;            FuncGen();&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        foreach (PrintersFunc p in printers)&lt;br&gt;        {&lt;br&gt;            p();&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        for (int i = 0; i &amp;lt; 10; i++)&lt;br&gt;        {&lt;br&gt;            setters[i](i + 1);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        foreach (PrintersFunc p in printers)&lt;br&gt;        {&lt;br&gt;            p();&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        // if the output was suppose to be similar to:&lt;br&gt;        // 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10&lt;br&gt;        // then this code follows the same behavior.&lt;br&gt;    }&lt;br&gt;}</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#483332</link><pubDate>Fri, 21 Oct 2005 08:38:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:483332</guid><dc:creator>Dan Muller</dc:creator><description>Yes, James, that's the expected output. Sorry that I forgot to include it with my examples.&lt;br&gt;&lt;br&gt;In the discussion of BradA's referenced blog, Ian Griffiths asks the right question, and the answer is that the sharing of lexical variables, not just values, is expected of closures. This is the definition that Lisp has used since long before Ruby or C# existed.&lt;br&gt;&lt;br&gt;The only sense in which anonymous methods could be considered different from closures is that they are _methods_ rather than functions. But this is a fairly trivial difference. In essence, the implicit 'this' variable is just another lexical variable that is captured in the closure.&lt;br&gt;</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#483380</link><pubDate>Fri, 21 Oct 2005 11:45:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:483380</guid><dc:creator>abhinaba</dc:creator><description>I interpreted the definition of lexical closure is to share values not variables. In case it is sharing of variables then C# does implement lexical closure. This brings up an interesting thought, why do people in the C# team including BradA and Eric always say that anonymous methods are not closures?&lt;br&gt;&lt;br&gt;Anyways, all these discussions sooner or later lead to Lisp/Scheme/Ruby. I guess I have to start on Lisp soon.....</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#483430</link><pubDate>Fri, 21 Oct 2005 16:39:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:483430</guid><dc:creator>Dan Muller</dc:creator><description>abhinaba: That's indeed a good question. If I had to guess based on that other blog, I'd say BradA is relying on C2 and wikipedia for definitions. Not an unreasonable notion, but it happens to fail in this instance. I think the Common Lisp definition is arguably a better choice due to its age.&lt;br&gt;&lt;br&gt;You might consider drawing their attention to this exchange to see what they have to say.&lt;br&gt;&lt;br&gt;As I understand it, ML, being a pure functional language, has immutable 'variables'. In such languages, the distinction between name/value and name/variable mappings is irrelevant. Thus the wikipedia entry's choice of using ML as an example is unfortunate.&lt;br&gt;&lt;br&gt;I definitely recommend learnign Lisp. I studied the pre-standardization document (Guy Steele's &amp;quot;Common Lisp&amp;quot; ) in detail early in my career (just prior to standardization), and it helped me immensely in understanding many issues of programming language design.&lt;br&gt;&lt;br&gt;Nowadays I doubt I'd have the fortitude to read through a language specification like this, though. Too busy reading blogs. :)&lt;br&gt;</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#495208</link><pubDate>Mon, 21 Nov 2005 15:10:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:495208</guid><dc:creator>Jon Harrop</dc:creator><description>Dan Muller wrote:&lt;br&gt;&amp;gt; As I understand it, ML, being a pure functional&lt;br&gt;&amp;gt; language, has immutable 'variables'. In such&lt;br&gt;&amp;gt; languages, the distinction between name/value and&lt;br&gt;&amp;gt; name/variable mappings is irrelevant. Thus the&lt;br&gt;&amp;gt; wikipedia entry's choice of using ML as an example&lt;br&gt;&amp;gt; is unfortunate.&lt;br&gt;&lt;br&gt;ML is not a pure functional language, it is an impure functional language (Haskell is an example of a pure functional language). So ML has both mutable and immutable variables.&lt;br&gt;&lt;br&gt;The OCaml equivalent of the original example programs is simply:&lt;br&gt;&lt;br&gt;let arr =&lt;br&gt;  Array.init 11 (fun i () -&amp;gt; Printf.printf &amp;quot;%d &amp;quot; i)&lt;br&gt;Array.iter (fun f -&amp;gt; f ()) arr&lt;br&gt;&lt;br&gt;The first line creates an array of closures, each of which prints its own index in the array. The second line applies the final argument &amp;quot;()&amp;quot; to each of the closures, invoking them in turn and printing out the consecutive integers 0..10.&lt;br&gt;&lt;br&gt;I have no idea whether or not C# supports first-class lexical closures. I do know that other languages will have a tough time trying to beat the brevity and performance of ML though.&lt;br&gt;&lt;br&gt;Cheers,&lt;br&gt;Jon.&lt;br&gt;&lt;br&gt;PS: Don't try to learn anything about functional programming from Wikipedia - the articles are mostly awful and they seem to be getting worse...&lt;br&gt;</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#660493</link><pubDate>Sun, 09 Jul 2006 11:16:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:660493</guid><dc:creator>Christopher Atkins</dc:creator><description>I believe that the point Ian Griffiths made on BradA's blog about the definition of closure being too implementation specific is at the center of the confusion here. &amp;nbsp;&lt;br&gt;&lt;br&gt;In Lisp, the compiler actually creates &amp;quot;a closure&amp;quot;, a container if you will, for the lexical context of the function. &amp;nbsp;In .NET, according to the discussion on BradA's blog and inferred from Eric Gunnerson's comments on Channel9, the variables referenced by the anonymous methods are moved from the stack to the heap so that the &amp;quot;closed over&amp;quot; variables can be referenced in a shared manner independent of the lexical scope where they were declared.&lt;br&gt;&lt;br&gt;In short, the difference between &amp;quot;a closure&amp;quot; and an &amp;quot;anonymous method&amp;quot; is semantics. &amp;nbsp;They both form a _logical_ lexical closure. &amp;nbsp;They only vary in their implementations.</description></item><item><title>Espacio de Dario Quintana &amp;raquo; Predicados y especificaciones</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#1558074</link><pubDate>Tue, 30 Jan 2007 21:10:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1558074</guid><dc:creator>Espacio de Dario Quintana » Predicados y especificaciones</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://blog.darioquintana.com.ar/2006/10/07/predicados-y-especificaciones/"&gt;http://blog.darioquintana.com.ar/2006/10/07/predicados-y-especificaciones/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#2785962</link><pubDate>Tue, 22 May 2007 10:26:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2785962</guid><dc:creator>Kiran A Digumarti</dc:creator><description>&lt;p&gt;This works....&lt;/p&gt;
&lt;p&gt;using System;&lt;/p&gt;
&lt;p&gt;using System.Collections.Generic;&lt;/p&gt;
&lt;p&gt;using System.Text;&lt;/p&gt;
&lt;p&gt;namespace Assignment14&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;class AnonymousExample {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public delegate string proc1();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static proc1 delay(proc1 p)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string value = null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return delegate()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (value == null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;value = p.Invoke();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return value;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return value;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;};&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public string foo()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(&amp;quot;Thinking about foo&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return &amp;quot;fu&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public string bar()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(&amp;quot;thinking about bar&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return &amp;quot;British American Racing&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static void Main26()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AnonymousExample ae = new AnonymousExample();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;proc1 p, q, r, s;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r = ae.foo;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s = ae.bar;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;p = delay(r);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = delay(s);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(p.Invoke());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(q.Invoke());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(p.Invoke());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(q.Invoke());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item><item><title>  More on Thread-Safe Invocation at  Discord&amp;#038;Rhyme</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#4369215</link><pubDate>Mon, 13 Aug 2007 18:41:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4369215</guid><dc:creator>  More on Thread-Safe Invocation at  Discord&amp;Rhyme</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://kohari.org/2007/08/13/more-on-thread-safe-invocation/"&gt;http://kohari.org/2007/08/13/more-on-thread-safe-invocation/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Ruby.NET</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#6469890</link><pubDate>Thu, 22 Nov 2007 15:30:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6469890</guid><dc:creator>I know the answer (it's 42)</dc:creator><description>&lt;p&gt;I had blogged earlier about Gardens Point Ruby.NET . After I read Don Box writing about it, I decided&lt;/p&gt;
</description></item><item><title>Generation 5 &amp;raquo; Keeping Track Of State In Asynchronous Callbacks</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#8569762</link><pubDate>Mon, 02 Jun 2008 20:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8569762</guid><dc:creator>Generation 5 &amp;raquo; Keeping Track Of State In Asynchronous Callbacks</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://gen5.info/q/2008/06/02/keeping-track-of-state-in-asynchronous-callbacks/"&gt;http://gen5.info/q/2008/06/02/keeping-track-of-state-in-asynchronous-callbacks/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: C#: Anonymous methods are not closures</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#8648822</link><pubDate>Tue, 24 Jun 2008 23:16:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8648822</guid><dc:creator>Plmnywix</dc:creator><description>&lt;p&gt;Open this post and read what I think about that:, &lt;/p&gt;
</description></item><item><title>
  Anonymous delegates in C# &amp;raquo; blog vipa
</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#9110553</link><pubDate>Mon, 17 Nov 2008 17:42:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9110553</guid><dc:creator>
  Anonymous delegates in C# &amp;raquo; blog vipa
</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://coffee3.org/2008/11/17/anonymous-delegates-in-csharp/"&gt;http://coffee3.org/2008/11/17/anonymous-delegates-in-csharp/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Strona ZPP: Anonimowe metody w j??zyku C#</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#9383323</link><pubDate>Thu, 29 Jan 2009 19:20:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9383323</guid><dc:creator>Strona ZPP: Anonimowe metody w j??zyku C#</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://technojazda.wikidot.com/csharpclosures"&gt;http://technojazda.wikidot.com/csharpclosures&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>ReSharper: Access to modified closure</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#9534239</link><pubDate>Mon, 06 Apr 2009 22:20:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9534239</guid><dc:creator>Patrick Steele's .NET Blog</dc:creator><description>&lt;p&gt;On the advice of Jay Wren , I decided to try our ReSharper 4.1 .&amp;amp;#160; I had previously installed DevExpress&lt;/p&gt;
</description></item><item><title>ReSharper: Access to modified closure</title><link>http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx#9534258</link><pubDate>Mon, 06 Apr 2009 22:26:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9534258</guid><dc:creator>Patrick Steele</dc:creator><description>&lt;p&gt;On the advice of Jay Wren , I decided to try our ReSharper 4.1 .&amp;amp;#160; I had previously installed DevExpress&amp;amp;#39;&lt;/p&gt;
</description></item></channel></rss>