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

  • Home
  • SEARCH
  • 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 7416789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:34:02+00:00 2026-05-29T07:34:02+00:00

I was having a look at the IL generated for a very simple method

  • 0

I was having a look at the IL generated for a very simple method because I want to do a small bit of reflection emitting myself and I came across something that is mentioned in the comments in this question (but was not the question):Using Br_S OpCode to point to next instruction using Reflection.Emit.Label and nobody answered it and I am wondering about it. so…

If I have a method like this:

    public string Test()
    {            
        return "hello";
    }

and then I run ILDASM on it I see the IL is this:

.method public hidebysig instance string 
        Test() cil managed
{
  // Code size       11 (0xb)
  .maxstack  1
  .locals init ([0] string CS$1$0000)
  IL_0000:  nop
  IL_0001:  ldstr      "hello"
  IL_0006:  stloc.0
  IL_0007:  br.s       IL_0009
  IL_0009:  ldloc.0
  IL_000a:  ret
}

The part that I find curious is:

  IL_0007:  br.s       IL_0009
  IL_0009:  ldloc.0

The first line is doing an Unconditional Transfer to the second line. What is the reason for this operation, doesn’t it do nothing?

EDIT

It seems my question was phrased badly as there is some confusion over what I wanted to know. The last sentence should maybe be something like this:

What is the reason that the compiler has output this unconditional transfer statement when it seems to be serving no purpose?

UPDATE

The suggestion that it was for a breakpoint made me think to try and compile this in Release mode and sure enough the part that I am interested in vanished and the IL became just this (which is why I jumped the gun and thought that the breakpoint answer was the reason):

.method public hidebysig instance string 
        Test() cil managed
{
  // Code size       6 (0x6)
  .maxstack  8
  IL_0000:  ldstr      "hello"
  IL_0005:  ret
} 

The question of “why is it there” still plays on my mind though – if it is not the way the compiler always works and it is not for some useful debugging reason (like having somewhere to place a breakpoint) why have it at all?

I guess the answer is probably: “just the way it has been made, no solid reason, and it doesn’t really matter because the JIT will sort it all out nicely in the end.”

I wish I’d not asked this now, this is going to ruin my acceptance percentage!! 🙂

  • 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-29T07:34:02+00:00Added an answer on May 29, 2026 at 7:34 am

    The first of the two instructions is part of the standard code for the return statement, the second instruction is part of the boilerplate code for the method.

    The return statement puts the return value in a local variable, then it jumps to the exit point of the method:

    IL_0001:  ldstr      "hello"
    IL_0006:  stloc.0
    IL_0007:  br.s       IL_0009
    

    The boilerplate code of the method gets the return value from the local variable and then exits from the method:

    IL_0009:  ldloc.0
    IL_000a:  ret
    

    In the IL code that the compiler creates, a method always have a single exit point. That’s why the return statement jumps to that location instead of just exiting the function directly. The code for the return statement is always the same, so there is always a branch even if it jumps to the next instruction.

    The compiler often produces IL code that looks inefficient, because the JIT compiler optimises the code. The compiler produces unoptimised, simple and predictable code which is easier for the JIT compiler to optimise.

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

Sidebar

Related Questions

I've been having a look at making changes to the partial classes generated from
So I came across this thread and it works very well - How to
I was having a look at this tutorial at Sun on command line I/O.
I've been having a look at several MVC frameworks (like rails, merb, cakephp, codeignitier,
I am having a look af a big C++ project with more than 100
Can anyone recommend a free grid/graphing component for C#/.NET? I'm having a look at
Hello I am having a hard time making this UI element look the way
I am having trouble with the delimiter in the TStringList Class. Take a look:
My problem is that I'm having trouble specifying paths for Lua to look in.
I am programming C on cygwin windows. After having done a bit of C

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.