I'm interpreting your question to mean:
When the string is const, is code that references the
Length property of the string replaced with a
hard-coded absolute value (the string length)
at compile-time? Or does the compiler generate
code that accesses the Length property at run-time,
as it would for a non-const string?
Using your example:
public const string AnString = "An string value"; Console.WriteLine(AnString.Length > 5);
Does the compiler generate code that actually compares
the Length property to 5, or does it generate code that
literally uses the expression 15 > 5 because the length
of the string is fixed and can not be changed at run time?
Console.WriteLine(15 > 5);
Or does it generate code that skips a comparison altogether
and just generates code that uses a true/false bool? e.g. -
I haven't checked the Standard but I would expect that to
be an implementation-specific detail (or feature).