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

The Archive Base Latest Questions

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

This was mentioned in my other question and I thought it might be useful

  • 0

This was mentioned in my other question and I thought it might be useful to add it to the record. In the following program, which, if any, of the locally defined delegates are cached between calls to the Work method instead of being created from scratch each time?

namespace Example {     class Dummy     {         public int age;     }      class Program     {         private int field = 10;          static void Main(string[] args)         {             var p = new Program();              while (true)             {                 p.Work();             }         }          void Work()         {             int local = 20;              Action a1 = () => Console.WriteLine(field);             Action a2 = () => Console.WriteLine(local);             Action a3 = () => Console.WriteLine(this.ToString());             Action a4 = () => Console.WriteLine(default(int));             Func<Dummy, Dummy, bool> dummyAgeMatch = (l, r) => l.age == r.age;              a1.Invoke();             a2.Invoke();             a3.Invoke();             a4.Invoke();             dummyAgeMatch.Invoke(new Dummy() { age = 1 }, new Dummy(){ age = 2 });         }     } } 
  • 1 1 Answer
  • 1 View
  • 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:55:26+00:00Added an answer on May 11, 2026 at 1:55 am

    Based on what Reflector shows, the last two (a4 and dummyAgeMatch) are cached by the MS C#3.0 compiler (in fields called ‘CS$<>9_CachedAnonymousMethodDelegate5’ and ‘CS$<>9_CachedAnonymousMethodDelegate6’ in my particular build).

    These ones can be cached, whereas obviously the others depend on captured variables.

    I don’t believe the behaviour is mandated by the spec, but the Mono compiler behaves in much the same way (with different variable names).

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

Sidebar

Related Questions

I am completely perplexed. I asked this question and it (any mentioned solution) doesn't
In another question , someone mentioned this site which blew me away: http://zoomii.com Does
This is just an idle thought I had when reading this other question: What
In this question , I mentioned my assumption that rubyforge gems are more official,
Some people have mentioned RockScroll and MetaScroll in This Question , but those only
I came across this question on a website. As mentioned there, it was asked
This might be a trivial question, but I have not found anything about it,
While answering this question regarding safe escaping of filename with spaces (and potentially other
As Cody Gray mentioned when answering my other question here , Raymond Chen talks
I know this issue being mentioned before, but resolutions there didn't apply. I'm having

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.