Why can't I have "public static const string S = "stuff"; in my Class?
When trying to compile my class I get an error:
The constant
'NamespaceName.ClassName.CONST_NAME'
cannot be marked static.
at the line:
public static const string CONST_NAME = "blah";
I could do this all of the time in Java. What am I doing wrong? And why doesn't it let me do this?
Solution 1:
A const
object is always static
.
Solution 2:
From the C# language specification (PDF page 287 - or 300th page of the PDF):
Even though constants are considered static members, a constant declaration neither requires nor allows a static modifier.