How best to implement publicly accessible constants in C#
- by DanM
There seem to be three choices for implementing publicly accessible constants in C#. I'm curious if there are any good reason to choose one over the other or if it's just a matter of personal preference.
Choice 1 - private field plus property getter
private const string _someConstant = "string that will never change";
public string SomeConstant
{
get { return _someConstant; }
}
Choice 2 - property getter only
public string SomeConstant
{
get { return "string that will never change"; }
}
Choice 3 - public field only
public const string SomeConstant = "string that will never change";
Which do you recommend and why?