When should I use a struct instead of a class?

后端 未结 15 2134
臣服心动
臣服心动 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条回答
  •  长情又很酷
    2020-11-22 13:17

    I think the best answer is simply to use struct when what you need is a collection of properties, class when it's a collection of properties AND behaviors.

提交回复
热议问题