in .Net, integers are signs, which means they are stored on the stack. Integers are also classes (usually System.Int32). They have methods like CompareTo, Equals, ... Thus, they must accept more than four bytes on the stack. The example below shows that they take exactly 4 bytes:
unsafe static void Main()
{
int a = 2, b = 4;
Console.WriteLine("Adress of a : {0}", (int)&a);
Console.WriteLine("Adress of b : {0}", (int)&b);
Console.WriteLine("Size of integer: {0}", (int)(&a) - (int)(&b));
}
Output:
Adress of a : 1372876
Adress of b : 1372872
Size of integer: 4
Is the CLR a special treatment for integers and other values ββ(float, long, double, ...)?
Mathieu
source
share