Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

12
  • 121
    The static point seems to be the most important and useful point - consts are implicitly static
    – LCJ
    Commented Jan 21, 2013 at 14:00
  • 42
    The part about reference values is the most important one. Const values can be optimized away. Commented Jun 5, 2013 at 7:03
  • 32
    readonly variables can be changed outside the constructor (reflection). It's only the compiler that tries to hinder you from modifying the var outside the constructor.
    – Bitterblue
    Commented Jun 5, 2013 at 14:10
  • 14
    @mini-me readonly variables are not allowed to be changed once the constructor has finished, even via reflection. The runtime happens to not enforce this. The runtime also happens not to enforce that you don't change string.Empty to "Hello, world!", but I still wouldn't claim that this makes string.Empty modifiable, or that code shouldn't assume that string.Empty will always be a zero-length string.
    – user743382
    Commented Apr 14, 2014 at 11:55
  • 12
    blogs.msmvps.com/jonskeet/2014/07/16/… is an interesting read only the overhead cost of readonly
    – CAD bloke
    Commented Aug 5, 2014 at 21:52