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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:28:11+00:00 2026-05-26T16:28:11+00:00

I wrote this very basic programm to examine what the compiler is doing behind

  • 0

I wrote this very basic programm to examine what the compiler is doing behind the scenes:

class Program
{
    static void Main(string[] args)
    {
        var increase = Increase();
        Console.WriteLine(increase());
        Console.WriteLine(increase());
        Console.ReadLine();
    }

    static Func<int> Increase()
    {
        int counter = 0;
        return () => counter++;
    }
}

Now when I look at the code with Reflector I do see that the compiler generates a class for my closure like that:

[CompilerGenerated]
private sealed class <>c__DisplayClass1
{
    // Fields
    public int counter;

    // Methods
    public int <Increase>b__0()
    {
        return this.counter++;
    }
}

That’s fine and I’m aware that he needs to do that to handle my closure. However, what I can’t see is how he is actually using this class. I mean I should be able to find code that instantiates “<>c__DisplayClass1” somewhere, am I wrong?

EDIT

If I click on the increase method it looks like that:

private static Func<int> Increase()
{
    int counter = 0;
    return delegate {
        return counter++;
    };
}
  • 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. Editorial Team
    Editorial Team
    2026-05-26T16:28:11+00:00Added an answer on May 26, 2026 at 4:28 pm

    You should find it in the Increase method, which I’d expect to have an implementation along these lines:

    // Not actually valid C# code because of the names...
    static Func<int> Increase()
    {
        <>c__DisplayClass1 closure = new c__DisplayClass1();
        closure.counter = 0;
        return new Func<int>(closure.<Increase>b__0);
    }
    

    Reflector won’t show you that code unless you turn off its optimization, but it should be there. Either turn off Reflector’s optimization, or use ildasm.

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

Sidebar

Related Questions

This is a very basic question for JUnit testing. I wrote a program which
This is a very basic program for Uni which writes user data to a
This is a very simple bash script I wrote: #!/bin/bash ITEM_LIST=items.txt LOG_FILE=log.log TOTAL_ITEMS=$(wc -l
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote this tiny code: #include <stdio.h> int main() { size_t temp; temp =
I want to compile a very basic hello world level Cuda program under Linux.
I recent wrote this post: How best to store VERY large 2D list of
I'm having this very odd issue while trying to serialize a class for logging
I'm learning how to program the video camera in android and wrote a very
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .

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.