“const correctness” in C#

前端 未结 7 1433
执念已碎
执念已碎 2020-11-28 05:29

The point of const-correctness is to be able to provide a view of an instance that can\'t be altered or deleted by the user. The compiler supports this by pointing out when

相关标签:
7条回答
  • 2020-11-28 05:45

    To get the benefit of const-craziness (or pureness in functional programming terms), you will need to design your classes in a way so they are immutable, just like the String class of c# is.

    This approach is way better than just marking an object as readonly, since with immutable classes you can pass data around easily in multi-tasking environments.

    0 讨论(0)
提交回复
热议问题