I installed resharper and it suggested to me that I should modify some local variables to a const. I never heard of this, so I starting googling. MSDN sure enough has a bit of code of having local consts, but no explanation why. On stackoverflow I came across questions but had more to do with whether having a local const is faster than not having them.
So, I’m scratching my head here. Why is it possible to have a local const? Does it have to do with semantics? Is there some benefit? Maybe both?
Const have a main benefit: it’s value is unchangeable and this enforce code stability and solidness.
Let’s say you’ve to define some date format during some method execution and it’s valid for this one only. Why don’t you’d be using a constant?
You avoid human errors if you use constants if it’s possible to use them.