Somewhat academic question, but: How do value types like Int actually work?
I've used Reflector on mscorlib to find out how System.Int32 is implemented, and it's just a Struct that inherits from System.ValueType. I was looking for something among the lines of an Array of Bits holding the value, but I only found a field that's declared int - which means it's a circular reference?
I mean, I can write "int i = 14;", but the number 14 needs to be stored somewhere somehow, but I couldn't find the "Array of 32-Bits" or a Pointer or something.
Is this some magic that the compiler does, and are these magic types part of the specification? (Similar to how System.Attribute or System.Exception are "special" types)
Edit: If I declare my own struct, I add fields to it. Those fields are of a built-in type, for example int. So the CLR knows that I hold an int. But how does it know that an int is 32-Bits, signed? Is it simply that the Specification specifies certain base types and therefore makes them "magic", or is there a technical mechanism? Hypothetical example: If I would want to declare an Int36, that is an Integer with 36 Bits, could I create a type that works exactly like an Int32 (apart from the 4 extra bits ofc) by specifying "Okay, set aside 36 bits", or are the built-in primitives set in stone and I would have to somehow work around this (i.e. by using an Int64 and code that only sets the last 36 Bits)?
As said, all very academic and hypothetical, but I always wondered about that.