Why does C# disallow readonly local variables?

后端 未结 13 1282
萌比男神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 17:46

    I was that coworker and it wasn't friendly! (just kidding)

    I would not eliminate the feature because it's better to write short methods. It's a bit like saying you shouldn't use threads because they're hard. Give me the knife and let me be responsible for not cutting myself.

    Personally, I wanted another "var" type keyword like "inv" (invarient) or "rvar" to avoid clutter. I've been studying F# as of late and find the immutable thing appealing.

    Never knew Java had this.

提交回复
热议问题