📜  为什么在c#代码示例中将私有字段设为只读

📅  最后修改于: 2022-03-11 14:48:49.561000             🧑  作者: Mango

代码示例1
f it's private and readonly , the benefit is that you can't inadvertently change it from another part of that class after it is initialized. The readonly modifier ensures the field can only be given a value during its initialization or in its class constructor.