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 181343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:44:48+00:00 2026-05-11T14:44:48+00:00

I’ve been reading this article about closures in which they say: all the plumbing

  • 0

I’ve been reading this article about closures in which they say:

  • ‘all the plumbing is automatic’
  • the compiler ‘creates a wrapper class’ and ‘extends the life of the variables’
  • ‘you can use local variables without worry’
  • the .NET compiler takes care of the plumbing for you, etc.

So I made an example based on their code and to me, it seems as though closures just act similarly to regular named methods which also ‘take care of the local variables without worry’ and in which ‘all the plumbing is automatic’.

Or what problem did this ‘wrapping of local variables’ solve that makes closures so special / interesting / useful?

using System; namespace TestingLambda2872 {     class Program     {         static void Main(string[] args)         {             Func<int, int> AddToIt = AddToItClosure();              Console.WriteLine('the result is {0}', AddToIt(3)); //returns 30             Console.ReadLine();         }          public static Func<int, int> AddToItClosure()         {             int a = 27;             Func<int, int> func = s => s + a;             return func;         }     } } 

Answer

So the answer to this one is to read Jon Skeet’s article on closures that Marc pointed out. This article not only shows the evolution leading up to lambda expressions in C# but also shows how closures are dealt with in Java, an excellent read for this topic.

  • 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-11T14:44:49+00:00Added an answer on May 11, 2026 at 2:44 pm

    Your example isn’t clear, and doesn’t (IMO) show typical capture usage (the only thing captured is a, which is always 3, so not very interesting).

    Consider this text-book example (a predicate):

    List<Person> people = ... string nameToFind = ... Person found = people.Find(person => person.Name == nameToFind); 

    Now try it without a closure; you need to do a lot more work, even if we are lazy:

    PersonFinder finder = new PersonFinder(); finder.nameToFind = ... Person found = people.Find(finder.IsMatch); ... class PersonFinder {     public string nameToFind; // a public field to mirror the C# capture     public bool IsMatch(Person person) {         return person.Name == nameToFind;     } } 

    The capture approach extends further to lots of variables at different scopes – a lot of complexity that is hidden.

    Other than the names, the above is an approximation of what the C# compiler does behind the scenes. Note that when additional scopes are involved we start chaining the different capture classes (i.e. inner scopes have a reference to the capture class of outer scopes). Quite complex.

    Jon Skeet has a good article on this here, and more in his book.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.