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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:42:13+00:00 2026-05-29T12:42:13+00:00

If I look at the IL that is created in Linqpad for the two

  • 0

If I look at the IL that is created in Linqpad for the two following code snippets, I wonder what happens here.

In c#

int i = 42;

results in the following IL code

IL_0000:  ret

whereas in VB

Dim i As Integer = 42

it is

IL_0000:  ldc.i4.s    2A 
IL_0002:  stloc.0  

Apparently, the c# compiler understands the the value is never used and thus simply returns nothing. In VB.NET the actual code is translated.

Is that due to differences in compiler optimization or is there anything else at work?

Update: Just to clarify this – I just enter this one line into LinqPad and look at the IL it creates (most definitely by running the respective compiler). There is no program.

  • 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-29T12:42:14+00:00Added an answer on May 29, 2026 at 12:42 pm

    Taking away the linqpad question, I ran vbc and csc with /optimize+ /debug- on these programs:

    Module f
    
    Public Sub Main()
        Dim i As Integer = 42
    End Sub
    
    End Module
    

    and

    public static class f
    {
    
    public static void Main()
    {
        int i = 42;
    }
    
    }
    

    and got these CIL results from ILDASM:

    For the VB:

    .method public static void  Main() cil managed
    {
      .entrypoint
      .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) 
      // Code size       4 (0x4)
      .maxstack  1
      .locals init (int32 V_0)
      IL_0000:  ldc.i4.s   42
      IL_0002:  stloc.0
      IL_0003:  ret
    } // end of method f::Main
    

    For the C#:

    .method public hidebysig static void  Main() cil managed
    {
      .entrypoint
      // Code size       1 (0x1)
      .maxstack  8
      IL_0000:  ret
    } // end of method f::Main
    

    So, yes, at least in this respect csc is ‘smarter’ than vbc. But I bet the JITter would remove any difference at execution time.

    edit

    I checked, and actually the executed native code is different, at least on my system. I put in Console.ReadLine() calls in both to give me a chance to attach a debugger, and I got these disassemblies:

    From the VB:

    00000000  sub         rsp,38h 
    00000004  mov         dword ptr [rsp+20h],0 
    0000000c  mov         rax,7FF000434D8h 
    00000016  mov         eax,dword ptr [rax] 
    00000018  test        eax,eax 
    0000001a  je          0000000000000021 
    0000001c  call        FFFFFFFFE45BA230 
    00000021  mov         dword ptr [rsp+20h],2Ah 
    00000029  call        FFFFFFFFE26ABF20 
    0000002e  mov         qword ptr [rsp+28h],rax 
    00000033  nop 
    00000034  jmp         0000000000000036 
    00000036  add         rsp,38h 
    0000003a  ret 
    

    From the C#:

    00000000  sub         rsp,38h 
    00000004  mov         rax,7FF000534D8h 
    0000000e  mov         eax,dword ptr [rax] 
    00000010  test        eax,eax 
    00000012  je          0000000000000019 
    00000014  call        FFFFFFFFE45AA230 
    00000019  call        FFFFFFFFE391BF20 
    0000001e  mov         qword ptr [rsp+20h],rax 
    00000023  nop 
    00000024  jmp         0000000000000026 
    00000026  add         rsp,38h 
    0000002a  ret 
    

    Now, my assembley is pretty much non-existent, but even I can see that

    mov         dword ptr [rsp+20h],2Ah 
    

    in the from-VB refers to a constant value of hex 2A, which is 42 decimal. So there you go, it does execute more instructions in the end.

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

Sidebar

Related Questions

I have multiple buttons that gets created in a table which all look like
I've created a web page that is suppose to look like it has tabs
Hey all,(im a beginner in rails) i've created a controller that look like that:
I have two tables in my database that look like this CREATE TABLE IF
I have an array that created 5 objects. Each object has two strings and
Ok I created simple user control that look like this <%@ Control Language=C# AutoEventWireup=true
Im looking to create a control that would look like comic baloon. In WPF
I'm trying to create an Android ListView that will look like Instagram pictures feed
I'm trying to create a custom UIButton that should look like a UIButtonTypeRoundedRect. In
I'm trying to create a Python script that would : Look into the folder

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.