-2

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.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325

1 Answers1

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