Link Details

Link 730075 thumbnail
User 478055 avatar

By mitchp
via stackoverflow.com
Published: Jan 18 2012 / 09:44

When using lambda expressions or anonymous methods in C#, we have to be wary of the access to modified closure pitfall. For example:
  • 5
  • 0
  • 1495
  • 798

Comments

Add your comment
User 187417 avatar

sproketboy replied ago:

0 votes Vote down Vote up Reply

> again.....

User 265881 avatar

Topnotch replied ago:

0 votes Vote down Vote up Reply

This is really a change to fix compiler generated code that could cause subtle bugs. You would only notice the change if your code depends on the variable being visible outside of the loop's scope even though it was defined inside the loop in the code. Good comment by michelvoo:
"I wouldn't call it a breaking change, but rather an enabling change: code that was once subtly wrong will now start to behave as expected. Of course, some may have depended on the old behavior... – michielvoo"

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (5)



Voters Against This Link (0)



    Java Performance Optimization
    Written by: Pierre-Hugues Charbonneau
    Featured Refcardz: Top Refcardz:
    1. Design Patterns
    2. OO JS
    3. Cont. Delivery
    4. Java EE7
    5. HTML5 Mobile
    1. Node.js
    2. Debugging JavaScript
    3. OO JS
    4. JSON
    5. Ajax