why cannot declare const static string inside a class? Have to use static readonly
why cannot declare const static string inside a class? Have to use static readonly
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the C# language (as well as PHP),
constis implicitlystatic, so you don’t use both keywords together. This is unlike C and C++ whereconstdoesn’t say if a variable is static or not, just that its value is not modifiable.You declare a constant string like this:
There’s a slight difference between
constfields and staticreadonlyfields too, but both are similar in that you can’t change their values. Details are in this question.