How does it assign 6 to x
?
6
, the literal, is already an integer. The language is designed in a way that there are literal expressions within the syntax which are directly interpreted by the the compiler.
A plain 6
is an integer literal and already corresponds to an Int32
object with the value 6. The compiler does not actually need to call a constructor for literals but can create the objects directly. Depending on the type, there may be different syntaxes for different literals. For example a string literal "foo"
also makes the compiler create a string object with the value “foo” directly.
Note that this is nothing special to C# and its typing system. So whether Int32
is a value type or not does not actually matter (String
is not even a value type and there are still literals).