use MORE structs?

前端 未结 3 1742
心在旅途
心在旅途 2021-01-20 00:57

There have been several questions over the past few days about the proper use of null; here are three (one is mine):

  • Best Practice: Should functions r
3条回答
  •  醉酒成梦
    2021-01-20 01:50

    The big limitation (IMO) of a struct is that it ought to be immutable.

    I have several times defined and used a user-defined struct, for the reason you suggested (ie. because a struct can't be null); but I was then often (until I learned to never make them anything but immutable) burned by modifying a copy (sometimes an unnamed temporary copy) of a struct instance, instead of modifying the instance itself.

提交回复
热议问题