In the following method,
public void InspectList(IList<int> values)
{
if(values != null)
{
const string format = "Element At {0}";
foreach(int i in values)
{
Log(string.Format(format, i));
}
}
}
Does the use of const provide any benefit over just declaring the string as a string? Woudl it not be interned anyway?
True, in both cases it will be interned.
Marking it as a
constmakes your meaning clearer –do not touch this string variable, do not assign a different value to it.