Can structs contain fields of reference types

前端 未结 6 2097
一生所求
一生所求 2020-11-30 00:30

Can structs contain fields of reference types? And if they can is this a bad practice?

6条回答
  •  没有蜡笔的小新
    2020-11-30 00:43

    Yes they can.

    It depends.

    Many hold the stance that a struct should be immutable, and in this case, holding a reference to an object could mean it isn't.

    But it depends on the situation.

提交回复
热议问题