Why does C# disallow readonly local variables?

后端 未结 13 1184
萌比男神i
萌比男神i 2020-11-27 17:17

Having a friendly debate with a co-worker about this. We have some thoughts about this, but wondering what the SO crowd thinks about this?

13条回答
  •  一整个雨季
    2020-11-27 18:09

    Readonly means the only place the instance variable can be set is in the constructor. When declaring a variable locally it doesn't have an instance (it's just in scope), and it can't be touched by the constructor.

提交回复
热议问题