Why are structs stored on the stack while classes get stored on the heap(.NET)?

前端 未结 11 712
你的背包
你的背包 2020-12-01 03:05

I know that one of the differences between classes and structs is that struct instances get stored on stack and class instances(objects) are stored on the heap.

Sinc

11条回答
  •  抹茶落季
    2020-12-01 03:38

    Value types go on the stack, reference types go on the heap. A struct is a value type.

    There is no guaruantee about this in the specification though, so it might change in future releases:)

提交回复
热议问题