Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 103159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:04:46+00:00 2026-05-11T01:04:46+00:00

I found the following rather strange. Then again, I have mostly used closures in

  • 0

I found the following rather strange. Then again, I have mostly used closures in dynamic languages which shouldn’t be suspectable to the same ‘bug’. The following makes the compiler unhappy:

VoidFunction t = delegate { int i = 0; };  int i = 1; 

It says:

A local variable named ‘i’ cannot be declared in this scope because it would give a different meaning to ‘i’, which is already used in a ‘child’ scope to denote something else

So this basically means that variables declared inside a delegate will have the scope of the function declared in. Not exactly what I would have expected. I havn’t even tried to call the function. At least Common Lisp has a feature where you say that a variable should have a dynamic name, if you really want it to be local. This is particularly important when creating macros that do not leak, but something like that would be helpful here as well.

So I’m wondering what other people do to work around this issue?

To clarify I’m looking for a solution where the variables I declare in the delegete doesn’t interfere with variables declared after the delegate. And I want to still be able to capture variables declared before the delegate.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:04:47+00:00Added an answer on May 11, 2026 at 1:04 am

    It has to be that way to allow anonymous methods (and lambdas) to use local variables and parameters scoped in the containing method.

    The workarounds are to either use different names for the variable, or create an ordinary method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On the MSDN, I have found following: public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string
I found the following which shows how to delete an attribute from XML in
I found the following lines in a makefile tutorial, but I have some problem
I have a rather unexpected result with the following code: ABAddressBookRef addressBook = ABAddressBookCreate();
We have the following piece of code (idea for this code was found on
Recently I came across a gcc extension that I have found rather useful: __attribute__(cleanup)
I have the following XML file, the file is rather large and i haven't
I have the following Particle script (as found and edit from teh webs!): http://jsfiddle.net/neuroflux/hSkFX/1/
I'm following (or rather not following!) the tutorial found here: http://www.flashuser.net/flash-tricks/tips-tricks-10-using-drag-drop-in-actionscript-3-0.html I've drawn a
I'm customizing my zsh prompt and have found the following to check if there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.