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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:16:20+00:00 2026-06-13T12:16:20+00:00

If you get under the hood, value types in C# are treated very specially

  • 0

If you get under the hood, value types in C# are treated very specially by compiler/CLR. But types internal to CLR are treated even more specially. Here is what I mean:

int a = 5;
int b = 10;
int с = a + b;
a.CompareTo(b);

You can hover with your mouse over int in Visual Studio and see that actually it is System.Int32 struct. That’s OK. Now you can grab ILDasm and look into what System.Int32 is: turns over that it is very simple struct with one field of type int32 (this is int32 internal to CLR) and there is no overloaded operator for addition.

So, how this int с = a + b works then? Again I grab ILDasm and look into IL. Turns out that there is no System.Int32 in IL code: compiler automatically understands that it should replace it with int32. And there is IL instruction add that works for couple of int32 on a stack. What amuses me even more, CLR allows to call instance methods for System.Int32 on int32. Looks like some black magic to me.

So, here goes the pure theoretical question: seems that System.Int32 is type like any other, could it be created in C# somehow? And if it could, could you do anything useful with it (actual int32 field is private)?

Edit: Ok, to make it a bit more clear: this question have nothing about int being alias to System.Int32. One can take provided example, replace int with System.Int32 and skip first paragraph after the example. The real question is about possibility to have valuetype [mscorlib]System.Int32 a in your IL code instead of just int32 a.

  • 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-06-13T12:16:21+00:00Added an answer on June 13, 2026 at 12:16 pm

    So, consider the following code:

        static void Main(string[] args)
        {
            int x = 5;
            Print(x);
            Console.ReadLine();
        }
    
        static void Print(object x)
        {
            int y = (int)x;
            Console.WriteLine(y);
        }
    

    in ILDasm:

    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      .maxstack  1
      .locals init ([0] int32 x)
      IL_0000:  nop
      IL_0001:  ldc.i4.5
      IL_0002:  stloc.0
      IL_0003:  ldloc.0
      IL_0004:  box        [mscorlib]System.Int32
      IL_0009:  call       void Test.Program::Print(object)
      IL_000e:  nop
      IL_000f:  call       string [mscorlib]System.Console::ReadLine()
      IL_0014:  pop
      IL_0015:  ret
    } // end of method Program::Main
    
    .method private hidebysig static void  Print(object x) cil managed
    {
      .maxstack  1
      .locals init ([0] int32 y)
      IL_0000:  nop
      IL_0001:  ldarg.0
      IL_0002:  unbox.any  [mscorlib]System.Int32
      IL_0007:  stloc.0
      IL_0008:  ldloc.0
      IL_0009:  call       void [mscorlib]System.Console::WriteLine(int32)
      IL_000e:  nop
      IL_000f:  ret
    } // end of method Program::Print
    

    [mscorlib]System.Int32 is used for boxing/unboxing only. When the variable is in stack, it’s always int32.


    From Int32 and int:

    It might be helpful to think of System.Int32 as a shadow type for int32.

    The following C# code:

    int x = 0;
    x.ToString();
    

    Is this in IL:

    ldc.i4.0
    stloc.0
    ldloca.s 0
    call instance class System.String [mscorlib]System.Int32::ToString()
    pop
    

    Notice how it’s passing an int32 into a seemingly incompatible System.Int32
    struct. The engine allows this cause it has been hardwired to recognise
    System.Int32 as the shadow type of int32.

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

Sidebar

Related Questions

I was under the impression that I could get the value of a select
I'm trying to get to grips with what hibernate is doing under the hood,
I wonder is it possible to get cookies under another domain rather than my
I can get the word under the cursor with or , and I can
I'm trying to get perl running under on my Apache 2 macports install. I'm
I'm writing a Vim script. How can I get the word under the cursor
Under what exact circumstances do @SessionAttributes get cleared? I've discovered some confusing behaviour when
Can I get a threads suspend count under Windows CE, using C or Visual
I'm trying to get emacs tramp running under Windows XP to work over putty
I'm trying to get the footer on a webpage under my content, regardless of

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.