Why does C# disallow readonly local variables?

Brian Genisio picture Brian Genisio · Jan 14, 2009 · Viewed 22.6k times · Source

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?

Answer

andriej picture andriej · Apr 29, 2011

I think it's a poor judgement on part of C# architects. readonly modifier on local variables helps maintain program correctness (just like asserts) and can potentially help the compiler optimize code (at least in the case of other languages). The fact that it's disallowed in C# right now, is another argument that some of the "features" of C# are merely an enforcement of personal coding style of its creators.