<?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>The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx</link><description>First we'll look at how they're implemented.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686525</link><pubDate>Wed, 02 Aug 2006 18:12:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686525</guid><dc:creator>Rob Ender</dc:creator><description>This is why Java went with &amp;quot;anonymous inner classes can only access final parameters and local variables&amp;quot;. &amp;nbsp;No subtle side-effects here!&lt;br&gt;&lt;br&gt;If C#2.0 allows you to write subtly incorrect code, why not just get rid of that damned &amp;quot;can't declare the same variable in nested scopes&amp;quot; compiler error too?&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686585</link><pubDate>Wed, 02 Aug 2006 18:52:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686585</guid><dc:creator>Lionell Griffith</dc:creator><description>I thought the object of objects was that they could be used without knowledge of their internals. &amp;nbsp;It seems here that you need to know the internals of BOTH the objects you are using and the object compiler. &amp;nbsp;This is progress? &amp;nbsp;Looks to me to be nothing but fire and motion to distract the competition.&lt;br&gt;&lt;br&gt;I would much rather do structured and object oriented coding in C where I can know what is going on because I explcitly made it work that way. &amp;nbsp;Oh wait. &amp;nbsp;That's what I have been doing for almost 15 years. &amp;nbsp;Never mind.&lt;br&gt;&lt;br&gt;Thanks for reminding me of why I still don't want to use C++ or C#. &amp;nbsp;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686604</link><pubDate>Wed, 02 Aug 2006 19:14:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686604</guid><dc:creator>Tyler Reddun</dc:creator><description>Allowing the lambada function to access data in the local scope of the function seems like it's the wrong answer. The lambada exists longer then the local varabile so it would be a scoping issue. Allowing it just seems to be asking for trouble.&lt;br&gt;&lt;br&gt;Not that I would have even know that it did that, that is not something I would ever try myself. It just seems to be asking for trouble.</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686627</link><pubDate>Wed, 02 Aug 2006 19:30:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686627</guid><dc:creator>HA HA HA</dc:creator><description>tylar - teh scopign isue is resolved by the rule that a varable exists as long as sombody has a refrance to it. easy. i mean 'easy' in teh abstarct.&lt;br&gt;&lt;br&gt;whe're it gets weird is if youve got multipal nestad scopes invloved. say a closuare returnign a closure waht raturns a colsure. u can have moare then one closure runign around loose with reefrences to theh same object which was mabe orignaly on the stack. so if that objects a int or somthing the compilar also has to know to put on the heep an onyl put a refrence on the stack. so it can outlive the stdackframe. &lt;br&gt;&lt;br&gt;wondar if u can do thatwith a registar varable? hyuk huyk hyuk!</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686630</link><pubDate>Wed, 02 Aug 2006 19:33:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686630</guid><dc:creator>HA HA HA</dc:creator><description>linel - why do u need to know the intrenals? use it an it wroks. how meany poeople who wriate vrtual functoins or use multaple in heritance know about vtables?</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686633</link><pubDate>Wed, 02 Aug 2006 19:37:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686633</guid><dc:creator>zahical</dc:creator><description>Funny thing, that the argument of ‘not knowing what is happening’ is being used to bash C++ or C#. I think that, for the sake of the argument, one can say that we lost track of what’s happening the moment we stopped programming in assembler or the /O2 switch appeared on the command line of the compiler. Or possibly, the moment when everyone stopped developing their own OSes – just to keep things in control. &lt;BR&gt;&lt;BR&gt;And on the other hand – what’s not to know in the example with the anonymous delegates? I know _exactly_ what is happening – the local variable referenced in the body of the anonymous delegate and in the body of its lexically-enclosing method is one and the same, and so any changes to it are visible in both places. &lt;BR&gt;&lt;BR&gt;MS could change the implementation someday but if the end result is the same I’d still know what’s happening. &lt;BR&gt;&lt;BR&gt;You don’t need to know the internals of this to know what’s happening. Of course, the internals are very interesting and I think they illustrate very well Raymond’s point about the “kernel idea” and then just “doing what has to be done”. &lt;BR&gt;&lt;BR&gt;Anyway, judging by yesterday’s and today’s comments it actually turned out that this actually is ‘not actually a .NET blog’. :-) </description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686634</link><pubDate>Wed, 02 Aug 2006 19:39:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686634</guid><dc:creator>Matt</dc:creator><description>A notable point which annoys the hell out of me but which is beautifully illustrated by your post is : &lt;BR&gt;&lt;BR&gt;// Autogenerated by the compiler &lt;BR&gt;class __AnonymousClass$0 { &lt;BR&gt;&amp;nbsp;MyClass this$0; &lt;BR&gt;... &lt;BR&gt;&lt;BR&gt;Anyone who's ever serialized a large object graph via binary or soap formatters will spot it pretty quick. [Serializable] is missing. &lt;BR&gt;So any object graph containing one of these won't work. &lt;BR&gt;&lt;BR&gt;Really, **really** annoying. &lt;BR&gt;&lt;BR&gt;It is worth therefore being very aware of this distinction between 'easy' and 'hard' if you are going to use anonymous delegates and you ever use the invasive* serialization options. &lt;BR&gt;&lt;BR&gt;My team is probably going to have a look at whether we can binary hack our dll's on loading (we already use custom assembly resolvers so it's not as big a step as it sounds) to fake in the Serializable attributes at runtime. &lt;BR&gt;The ability to checkpoint almost the entire application to an arbitrary stream is *very* tempting. &lt;BR&gt;&lt;BR&gt;Not intended as a rant - just as an additional warning to anyone looking into this functionality and its side effects. &lt;BR&gt;&lt;BR&gt;* as opposed to the public properties / or special interface only XmlSerialization) &lt;BR&gt;&lt;BR&gt;&lt;DIV CLASS=post&gt;[&lt;I&gt;I don't know what attributes the compiler autogenerates. This was an informal discussion, not a specification. -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686694</link><pubDate>Wed, 02 Aug 2006 20:50:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686694</guid><dc:creator>Tom</dc:creator><description>The inner class should have access to the outer classes members and functions, regardless of protection (public, private, etc.) &amp;nbsp;If you consider the outer class as a translation unit, the that class' variables and functions can be considered &amp;quot;global&amp;quot; to the inner class. &amp;nbsp; The outer class should not have access to the inner class' members just as global functions do not have access to class' private members and functions (unless explicitly provided).&lt;br&gt;&lt;br&gt;In Raymond's &amp;quot;hard&amp;quot; example where the delegate accesses local variables, thus causing compiler generation of anonymous classes, I don't see how this is any different from a closure. &amp;nbsp;But I suppose that if there are two things that are hard for programmers to get (besides pointers and recursion -- but that's a different story) it's closrues and coroutines.&lt;br&gt;&lt;br&gt;With regard to Matt's complaint about serialization, I agree that is annoying. &amp;nbsp;I'd also say that it was a valid language/compiler design choice. &amp;nbsp;If you have the compiler automatically make closure/anon classes serializable, it will likely impose limits on the types of the data members in said class. &amp;nbsp;As a language designer, the tradoff would be making anon classes serializable but limited, or making anon classes unlimited but classes using delegates with anonymous classes unserializable.&lt;br&gt;&lt;br&gt;In the end, the anon classes are just syntactic sugar anyway, so why not just make named serializable delegates?</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686728</link><pubDate>Wed, 02 Aug 2006 21:40:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686728</guid><dc:creator>TW</dc:creator><description>I appreciate your C# insights, you have a skill at explaining things.&lt;br&gt;&lt;br&gt;However, I have to agree with many people that I don't completely grasp /why/ annoymous methods are so great. On a technical level what is gained over named delegates/ methods or just manually inlining the code? I guess I view it as another tool in my toolbox that I don't understand why it exists.</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686768</link><pubDate>Wed, 02 Aug 2006 22:17:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686768</guid><dc:creator>Azrael</dc:creator><description>Is this _actually_ how the CLR (or C#... is this language specific?) implements closures? Or only _conceptualy_? Doesn't it use a more compact representation?&lt;br&gt;&lt;br&gt;I can see why having a &amp;quot;complete&amp;quot; class with the environment as member variables may be better by &amp;quot;playing nice&amp;quot; (or &amp;quot;playing by the book&amp;quot;) with the CLR, so this is not a critique, only a question...&lt;br&gt;&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686776</link><pubDate>Wed, 02 Aug 2006 22:24:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686776</guid><dc:creator>Lionell Griffith</dc:creator><description>I have apparently hit a few hot buttons by saying that there are application classes that are not well solved by using .NET, C++, or C#. &amp;nbsp;They are good tools for low performance and simple CRUD centric applications on or off the internet and little else. &amp;nbsp;If that's what you do, expect your job to be outsourced in a few months to a year, if not next week. &amp;nbsp;&lt;br&gt;&lt;br&gt;Meanwhile, I will accomplish my goals my way.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686878</link><pubDate>Wed, 02 Aug 2006 23:57:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686878</guid><dc:creator>Anonymous</dc:creator><description>&amp;gt; Funny thing, that the argument of ‘not knowing what is happening’ is being used to bash C++ or C#. &lt;br&gt;&lt;br&gt;I find it funnier when MSDN already has a growing collection of articles on the intricacies of C#, yet some people claim that C++ is an abomination purely because there are some subtle details.&lt;br&gt;&lt;br&gt;I'm not sure if &amp;quot;HA HA HA&amp;quot;'s badly spelled rants are entirely serious - but fanboys are always funny, regardless of the object of their affection. &amp;nbsp;;)&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686880</link><pubDate>Wed, 02 Aug 2006 23:59:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686880</guid><dc:creator>b</dc:creator><description>Lionell: I think you missed the point of the article, which is about anonymous functions, and nothing to do with objects really. &amp;nbsp;The same idiosyncracies come up in other languages like LISP, which is functional, and has closures/lambda functions. &amp;nbsp;Your little rant didn't make much sense in context.&lt;br&gt;&lt;br&gt;TW: I tend to agree that anon functions bring in a lot more complexity than they're worth, at least from my experience, true closures can be pretty nasty. &amp;nbsp;Having the compiler generate anonymous functions for simple wrappers can be very handy though, if for nothing else to prevent the namespace from getting cluttered with trivial functions.</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686912</link><pubDate>Thu, 03 Aug 2006 00:25:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686912</guid><dc:creator>ccx</dc:creator><description>Gosh!&lt;br&gt;From what i use to see in other sites about programming languages, i thought people would say: &amp;quot;Great, finally C# has this new cool feature (closures)!&amp;quot;. Instead, what i see is people bashing a useful feature just because they don't quite understand it. Maybe recursion and virtual funcionts received the same bad looks when they were introduced...&lt;br&gt;&lt;br&gt;Am i the only one who **likes** when a programming language has more features? Or do everybody prefer minimalistic languages where you have to reimplement everything (including pass-by-reference, as in Java)?</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686951</link><pubDate>Thu, 03 Aug 2006 01:06:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686951</guid><dc:creator>Alyosha`</dc:creator><description>I am reminded of why I still don't want to use C every time I call malloc, every time I want to concatenate two strings (or for that matter, every time I want to model a 1:n relationship without fixing the value of n to some hard-coded constant), every time I want to deep copy a struct, and every time I check the same damn error code through ten call stack frames.&lt;br&gt;&lt;br&gt;It's not that we don't know how to program in C. &amp;nbsp;We do. &amp;nbsp;We know how bad it sucks. &amp;nbsp;We know that a C program can be replaced by an equivalent C++ or C# program in half the number of lines of code or less, without sacrificing performance (re-read Raymond Chen's series on building a Chinese / English dictionary). &amp;nbsp;We know that complexity scales exponetially with LOC; that's why we want the compiler to generate all that boilerplate, instead of fetishizing our ignorance and insisting on using an exacto knife for a job that requires a chainsaw.&lt;br&gt;&lt;br&gt;Lionell, if you can't be bothered to learn something new after 15 years, perhaps you should be the one worried about your future employability.</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686958</link><pubDate>Thu, 03 Aug 2006 01:13:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686958</guid><dc:creator>TW</dc:creator><description>ccx:&lt;br&gt;&lt;br&gt;I'm not opposed to anon methods. As you said I don't understand them so I have trouble seeing the usefulness. When I first started programming I thought the same thing about function pointers (functors, delegates, whatever). I now love them.&lt;br&gt;&lt;br&gt;I think part of the one sided-ness of the comments could just show who reads &amp;quot;The Old New Thing&amp;quot;. Namely, C/ C++ coders, not C#.&lt;br&gt;&lt;br&gt;Tools change, sometimes for the better, sometimes not. More tools are not a bad thing as long as they make the builders more productive and they enjoy using them.&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#686999</link><pubDate>Thu, 03 Aug 2006 01:49:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:686999</guid><dc:creator>bok</dc:creator><description>How does this work in a function containing multiple anonymous functions sharing a subset of local variables? I'd guess there'd either have to be one anonymous class created which shares all local variables referenced by any anonymous functions, or else a tree of anonymous classes referencing others depending on scope. The first seems like it could cause some massive memory leaks you wouldn't expect, but the second would be harder for the compiler and could easily generate some horrible code for all the dereferences in edge cases.&lt;br&gt;&lt;br&gt;(I'm not a C# programmer, but enjoyed the article btw...)&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#687231</link><pubDate>Thu, 03 Aug 2006 07:47:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:687231</guid><dc:creator>Anonymous</dc:creator><description>&amp;gt; The first seems like it could cause some massive memory leaks you wouldn't expect&lt;br&gt;&lt;br&gt;Two words: Garbage collection.&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#687309</link><pubDate>Thu, 03 Aug 2006 09:42:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:687309</guid><dc:creator>CN</dc:creator><description>Anonymous: The point of bok is more subtle, if anon method a keeps a reference to a local variable that's a huge dictionary z, and anon method b is a simple &amp;quot;return x + y&amp;quot; method, and b is shared by both anon functions, then the reference to z would be kept as long as there was any reference to anon method b. Not so good, or at least a real issue. It could be one of the cases where some knowledge of the actual implementation is needed.</description></item><item><title>An interesting read on anonymous methods.</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#687328</link><pubDate>Thu, 03 Aug 2006 10:17:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:687328</guid><dc:creator>Wouter van Vugt</dc:creator><description /></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#687400</link><pubDate>Thu, 03 Aug 2006 12:35:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:687400</guid><dc:creator>Matt</dc:creator><description>[I don't know what attributes the compiler auto generates. This was an informal discussion, not a specification. -Raymond]&lt;br&gt;&lt;br&gt;Sorry I wasn't trying to pick at anything in your example - your example was completely correct in not having the attribute. &lt;br&gt;I was just pointing out the limitations imposed by the silent hoops the compiler jumped through in the hard case.&lt;br&gt;&lt;br&gt;I agree simply adding it willy nilly would also be unrealistic since it would needlessly constrain things in another (far more important) direction.&lt;br&gt;&lt;br&gt;For the record I love anon delegates for two principle reasons neither of which rely on the 'hard' case.&lt;br&gt;As already mentioned by others they reduce the need for a separate function name (which as an event handler callback is probably not something you should be calling directly).&lt;br&gt;&lt;br&gt;But better still for a very small function (hopefully one or two lines) they provide greater 'cohesion' between the event subscription and the desired behaviour when it executes. I love this and find, when used well, it dramatically improves the readability of the code. I find reading the auto generated names from the designer a little ugly (but baring anon delegates have no better solution to offer :)</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#687410</link><pubDate>Thu, 03 Aug 2006 13:06:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:687410</guid><dc:creator>Paul</dc:creator><description>TW:&lt;br&gt;&lt;br&gt;One great use for anonymous delegates is unit testing event handlers; each test can be self contained and not require any additional methods to handle the event.</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#687455</link><pubDate>Thu, 03 Aug 2006 14:47:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:687455</guid><dc:creator>Azrael</dc:creator><description>CN: I don't really understand... Assuming that's something like this:&lt;br&gt;&lt;br&gt; &amp;nbsp;BigDictionary z;&lt;br&gt; &amp;nbsp;anon_a = delegate (x) { return z[x]; }&lt;br&gt; &amp;nbsp;anon_b = delegate (x,y) { return x + y; }&lt;br&gt;&lt;br&gt;And assuming that both anon_a and anon_b are returned, the compiler will generate one wrapper class and use for anon_a, but anon_b falls into what Raymond classified as the easy case.&lt;br&gt;&lt;br&gt;Unless anon_b directly references either z or anon_a, it is unrelated to z, therefore has no impact on the lifetime of z.&lt;br&gt;&lt;br&gt;It is easier if you think that each closure (delegate...) has an internal hashtable with the variables that it refers and are not parameters. This hashtable maps the name of the variable to a reference to it. The wrapper class thingy is only an implementation detail of C#/CLR.</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#687549</link><pubDate>Thu, 03 Aug 2006 17:27:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:687549</guid><dc:creator>bok</dc:creator><description>Azrael: I don't believe that was what CN meant. My original point was more the following situtation:&lt;br&gt;&lt;br&gt; int w;&lt;br&gt; BigDictionary z;&lt;br&gt; anon_a = delegate (x) { return z[x + w++]; } &lt;br&gt; anon_b = delegate (x) { return x + w++; } &lt;br&gt; if( something )&lt;br&gt; {&lt;br&gt; &amp;nbsp; &amp;nbsp;return anon_a;&lt;br&gt; }&lt;br&gt; else&lt;br&gt; {&lt;br&gt; &amp;nbsp; &amp;nbsp;return anon_b;&lt;br&gt; }&lt;br&gt;&lt;br&gt;Neither anonymous function fits into the easy case, because both reference 'w'. If anon_b happens to be returned, does the anonymous class include a live reference to 'z' as well? There can't be different anonymous classes which both contain 'w', in case either delegate modifies it.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#687742</link><pubDate>Thu, 03 Aug 2006 20:22:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:687742</guid><dc:creator>Patrick Smacchia</dc:creator><description>Here you can read some articles extracted from my book 'Practical .NET2 and C#2' where I explain the 'under the hood' of iterators in C#2 and how they are related to anonymous mehods:&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://www.theserverside.net/tt/articles/showarticle.tss?id=AnonymousMethods"&gt;http://www.theserverside.net/tt/articles/showarticle.tss?id=AnonymousMethods&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://www.theserverside.net/tt/articles/showarticle.tss?id=IteratorsWithC2"&gt;http://www.theserverside.net/tt/articles/showarticle.tss?id=IteratorsWithC2&lt;/a&gt;</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#688141</link><pubDate>Fri, 04 Aug 2006 05:21:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:688141</guid><dc:creator>Scott Tringali</dc:creator><description>Allowing the lambada function to access data in the local scope of the function seems like it's the wrong answer.&lt;br&gt;&lt;br&gt;Is that the forbidden dance function? &amp;nbsp;(&lt;a rel="nofollow" target="_new" href="http://en.wikipedia.org/wiki/Lambada"&gt;http://en.wikipedia.org/wiki/Lambada&lt;/a&gt;)&lt;br&gt;</description></item><item><title>Interesting Finds: August 2 </title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#688170</link><pubDate>Fri, 04 Aug 2006 06:25:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:688170</guid><dc:creator>Jason Haley</dc:creator><description /></item><item><title>weekly linkdump &amp;laquo; ???????? ?????????????????????????? &amp;laquo; developers.org.ua</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#688227</link><pubDate>Fri, 04 Aug 2006 08:02:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:688227</guid><dc:creator>weekly linkdump « ???????? ?????????????????????????? « developers.org.ua</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://www.developers.org.ua/archives/max/2006/08/04/weekly-linkdump-39/"&gt;http://www.developers.org.ua/archives/max/2006/08/04/weekly-linkdump-39/&lt;/a&gt;</description></item><item><title>Implementacja metod anonimowych w C# 2.0</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#689681</link><pubDate>Sat, 05 Aug 2006 22:59:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:689681</guid><dc:creator>my friend - visual</dc:creator><description>Na blogu oldnewthing pojawił się&amp;amp;amp;nbsp;trzy częściowy&amp;amp;amp;nbsp;artykuł o implementacji metod anonimowych w...</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#691486</link><pubDate>Tue, 08 Aug 2006 01:29:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:691486</guid><dc:creator>Neil</dc:creator><description>CN/Azrael/bok, the page Raymond linked to in a later entry seems to suggest that the comparative lifetime depends on the scope the variable is declared in. This means that you could declare z in an inner scope to w so that anon_b wouldn't need to keep a reference to z.</description></item><item><title>The implementation of anonymous methods in C# and its consequences</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#692347</link><pubDate>Tue, 08 Aug 2006 20:23:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:692347</guid><dc:creator>Eric Gunnerson's C# Compendium</dc:creator><description>Raymond wrote a really nice series of posts on this:&lt;br&gt;&lt;br&gt;Part 1&lt;br&gt;Part 2&lt;br&gt;Part 3&lt;br&gt;He also points out that...</description></item><item><title>re: The implementation of anonymous methods in C# and its consequences (part 1)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#692364</link><pubDate>Tue, 08 Aug 2006 20:43:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:692364</guid><dc:creator>Bill Cohagan</dc:creator><description>This is an interesting thread -- one that reminds me strongly of discussions threads I was involved in back in the '70s when we (a group of developers) were trying to get a grasp of closures and continuations in Scheme. I would strongly recommend that people interested in learning more about these take a look at Guy Steele's &amp;quot;The Lambda Papers&amp;quot; (&lt;a rel="nofollow" target="_new" href="http://library.readscheme.org/page1.html"&gt;http://library.readscheme.org/page1.html&lt;/a&gt;) An excellent introduction to the power of these ideas is Dan Friedman's &amp;quot;Little Schemer&amp;quot; book.&lt;br&gt;&lt;br&gt;These are certainly not concepts that are either new or Microsoft specific. They certainly are very powerful concepts and I for one am tickled pink that they are showing up in languages such as c#. &lt;br&gt;&lt;br&gt;If you don't take the time and effort to understand them they will remain &amp;quot;quirky&amp;quot; facets of the language. If you *do* take the time then I believe your code will be the better for it.&lt;br&gt;&lt;br&gt;Regards,&lt;br&gt; Bill&lt;br&gt;</description></item><item><title>The implementation of anonymous methods in C# and its consequences #1</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#693039</link><pubDate>Wed, 09 Aug 2006 10:51:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:693039</guid><dc:creator>DotNetKicks.com</dc:creator><description>You've been kicked (a good thing) - Trackback from DotNetKicks.com</description></item><item><title>Anonymous Methods -&gt; code bloat</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#699613</link><pubDate>Mon, 14 Aug 2006 18:09:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:699613</guid><dc:creator>Anonymous Methods -&gt; code bloat</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://blogs.dotninjas.dk/t4rzsan/archive/2006/08/14/1531.aspx"&gt;http://blogs.dotninjas.dk/t4rzsan/archive/2006/08/14/1531.aspx&lt;/a&gt;</description></item><item><title>An interesting read on anonymous methods.</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#738351</link><pubDate>Sun, 03 Sep 2006 22:07:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:738351</guid><dc:creator>Wouter van Vugt</dc:creator><description>An anonymous method is of course not anonymous at all, how else would you find it runtime if it were?</description></item><item><title>Tim Van Wassenhove  &amp;raquo; Blog Archive   &amp;raquo; Anonymous methods</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#758113</link><pubDate>Sun, 17 Sep 2006 00:13:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:758113</guid><dc:creator>Tim Van Wassenhove  » Blog Archive   » Anonymous methods</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://timvw.madoka.be/?p=622"&gt;http://timvw.madoka.be/?p=622&lt;/a&gt;</description></item><item><title>Tim Van Wassenhove &amp;raquo; Anonymous methods</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#802874</link><pubDate>Sun, 08 Oct 2006 03:03:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:802874</guid><dc:creator>Tim Van Wassenhove » Anonymous methods</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.timvw.be/anonymous-methods/"&gt;http://www.timvw.be/anonymous-methods/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>О сокрытии</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#872444</link><pubDate>Wed, 25 Oct 2006 12:31:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:872444</guid><dc:creator>Items</dc:creator><description>&lt;p&gt;Вместо эпиграфа: information hiding (1) In programming, the process of hiding details of an object or&lt;/p&gt;
</description></item><item><title>FYI: C# and VB Closures are per-scope</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#3145991</link><pubDate>Thu, 07 Jun 2007 21:13:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3145991</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>&lt;p&gt;This post assumes that you understand how closures are implemented in C#. They're implemented in essentially&lt;/p&gt;
</description></item><item><title>Implementation of anonymous methods in C#</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#3523387</link><pubDate>Mon, 25 Jun 2007 20:07:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3523387</guid><dc:creator>I hate Spaghetti (code)</dc:creator><description>&lt;p&gt;I read a nice and not too complicated post regarding the &amp;quot;behind the scenes&amp;quot; of anonymous methods. I&lt;/p&gt;
</description></item><item><title>Anonymous Delegates or DisposableActions?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#4313185</link><pubDate>Thu, 09 Aug 2007 22:41:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4313185</guid><dc:creator>Doron's .NET Space</dc:creator><description>&lt;p&gt;One of the most useful features of .NET 2.0 is anonymous delegates. They allow you to create &amp;quot;wrappers&amp;quot;&lt;/p&gt;
</description></item><item><title>Julio C??sar Carrascal Urquijo &amp;raquo; Archivo  &amp;raquo; D should have real closures.</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#4888737</link><pubDate>Thu, 13 Sep 2007 08:01:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4888737</guid><dc:creator>Julio C??sar Carrascal Urquijo » Archivo  » D should have real closures.</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://jcesar.totumo.net/2007/09/13/d-should-have-real-closures/"&gt;http://jcesar.totumo.net/2007/09/13/d-should-have-real-closures/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>New for Visual Studio 2008 - Support for anonymous methods and lambda expressions</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#5034737</link><pubDate>Fri, 21 Sep 2007 18:36:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5034737</guid><dc:creator>The Visual Studio Code Analysis Team Blog</dc:creator><description>&lt;p&gt;One of my favorite new features for Code Analysis in Visual Studio 2008 is our support for analyzing&lt;/p&gt;
</description></item><item><title>.Net Learning Curve  &amp;raquo; Blog Archive   &amp;raquo; C# nested classes (vs Java)</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#6338633</link><pubDate>Sat, 17 Nov 2007 18:44:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6338633</guid><dc:creator>.Net Learning Curve  » Blog Archive   » C# nested classes (vs Java)</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://dotnet.robertmao.com/2007/11/17/c-nested-classes-vs-java/"&gt;http://dotnet.robertmao.com/2007/11/17/c-nested-classes-vs-java/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>String-less ArgumentNullException</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#6715411</link><pubDate>Sun, 09 Dec 2007 21:58:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6715411</guid><dc:creator>Doron's .NET Space</dc:creator><description>&lt;p&gt;The post I wrote yesterday about Expression Trees has inspired to find some more cool usages for this&lt;/p&gt;
</description></item><item><title>Paul Stovell says&amp;#8230; &amp;raquo; Tip: &amp;#8220;Almost-anonymous&amp;#8221; methods in Visual Basic .NET</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#8575394</link><pubDate>Thu, 05 Jun 2008 17:45:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8575394</guid><dc:creator>Paul Stovell says&amp;#8230; &amp;raquo; Tip: &amp;#8220;Almost-anonymous&amp;#8221; methods in Visual Basic .NET</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.paulstovell.com/blog/almost-anonymous-methods-in-visual-basic-net"&gt;http://www.paulstovell.com/blog/almost-anonymous-methods-in-visual-basic-net&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>ReSharper: Access to modified closure</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#9534240</link><pubDate>Mon, 06 Apr 2009 22:20:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9534240</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/oldnewthing/archive/2006/08/02/686456.aspx#9534259</link><pubDate>Mon, 06 Apr 2009 22:26:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9534259</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><item><title>For once and for all: Delegates, Events, Anonymous Methods and Lambda Expressions &amp;laquo; Hungry for Knowledge</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#9634160</link><pubDate>Thu, 21 May 2009 21:53:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634160</guid><dc:creator>For once and for all: Delegates, Events, Anonymous Methods and Lambda Expressions &amp;laquo; Hungry for Knowledge</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://sdesmedt.wordpress.com/2009/05/21/for-once-and-for-all-delegates-events-anonymous-methods-and-lambda-expressions/"&gt;http://sdesmedt.wordpress.com/2009/05/21/for-once-and-for-all-delegates-events-anonymous-methods-and-lambda-expressions/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Anonymous Methods Internals | Beyond The Spec</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx#9777976</link><pubDate>Fri, 19 Jun 2009 02:52:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9777976</guid><dc:creator>Anonymous Methods Internals | Beyond The Spec</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://beyondthespec.com/blog/2009/06/19/anonymous-methods-internals/"&gt;http://beyondthespec.com/blog/2009/06/19/anonymous-methods-internals/&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>