Why can not declare a constant static string inside a class

why is it impossible to declare a constant static string inside a class? Must use static readonly

+3
source share
3 answers

In C # (like PHP) is constimplicit static, so you are not using both keywords together. This is not like C and C ++, where it constdoes not say whether a variable is static or not, just its value cannot be changed.

You declare a constant string as follows:

const string SomeConstant = "abc";

There is a slight difference between fields constand static fields readonly, but both are similar, since you cannot change their values. Details are in this question .

+20

, # , () . , , , , , - , . , , , . , () , . , , , (, ) . , .

+1

I wrote a blog about this that will give you a better understanding. Take a look at http://anishmarokey.blogspot.com/2009/09/const-vs-fields.html

basically primitivetypes used as constant other asstatic readonly

0
source

All Articles