问题:
I've read around about const
and static readonly
fields. 我已经阅读了有关const
和static readonly
字段的信息。 We have some classes which contains only constant values. 我们有一些仅包含常量值的类。 Used for various things around in our system. 用于我们系统中的各种事物。 So I am wondering if my observation is correct: 所以我想知道我的观察是否正确:
Should these kind of constant values always be static readonly
for everything that is public? 这些常量值是否应该对所有公共内容始终保持static readonly
? And only use const
for internal/protected/private values? 并且仅将const
用于内部/受保护/私有值吗?
What do you recommend? 您有什么推荐的吗? Should I maybe even not use static readonly
fields, but rather use properties maybe? 我是否应该甚至不使用static readonly
字段,而应该使用属性?
解决方案:
参考一: https://stackoom.com/question/3AaT/静态只读与常量参考二: https://oldbug.net/q/3AaT/Static-readonly-vs-const
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4482750