When should I use a struct instead of a class?

后端 未结 15 2275
臣服心动
臣服心动 2020-11-22 13:00

MSDN says that you should use structs when you need lightweight objects. Are there any other scenarios when a struct is preferable over a class?

Some people might ha

15条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 13:17

    when you don't really need behavior, but you need more structure than a simple array or dictionary.

    Follow up This is how I think of structs in general. I know they can have methods, but I like keeping that overall mental distinction.

提交回复
热议问题