when I dove into mscolib.dll
assembly I found that Int32 is a struct,but I don't know why we can apply "=" operator to Int32 like this Int32 num=5;
.it doesn't overload "=" operator within the Int32 struct.
Asked
Active
Viewed 72 times
-2

Patrick Hofman
- 153,850
- 22
- 249
- 325
-
1What does the `+` operator have to do with this? – Jeroen Vannevel Jan 24 '15 at 17:44
-
sorry,I made a mistake there.It should be "=" instead. – Hongyaoshun Jan 24 '15 at 17:59
1 Answers
1
The =
operator can not be overloaded. See Overloadable Operators. The =
operator always assigns the value on the right hand side to the variable on the left hand side.
For a value type (struct), it means that the entire value is copied into the variable.
For a type like Int32
, there are built in instructions in the processor that can do that copying. For structs that are so large that there is no instruction that can copy the entire value at once, there would be a loop that copies the bytes in the struct to the variable.

Guffa
- 687,336
- 108
- 737
- 1,005