Constants at property level

Topics: C# Language Design
Aug 4, 2014 at 1:34 PM
I always define constants as local as possible. So when I have a constant which solely is used by the getter and setter of the same property, wouldn't it make sense to declare it private to the entire property?
public int SomeValue
{
  private const string Key = "SomeValue"; // only "private" allowed
  get { return dict[Key]; }
  set { dict[Key] = value; }
}
Aug 5, 2014 at 10:57 AM
Why not just use the literal instead of defining a constant? If it is really only used for a single property, I don't see the advantage of defining it as constant.
Once compiled, constants aren't much (any?) different from literal constants and from a maintenance point of view, it's also not much of an advantage in my opinion.
Nov 12, 2014 at 4:13 PM
Without duplication there is no chance for a typo.