'const string' vs. 'static readonly string' in C#

前端 未结 5 1950
臣服心动
臣服心动 2020-12-02 06:39

In C#, what\'s the difference between

static readonly string MyStr;

and

const string MyStr;

?

5条回答
  •  臣服心动
    2020-12-02 06:50

    You can change the value of a static readonly string only in the static constructor of the class or a variable initializer, whereas you cannot change the value of a const string anywhere.

提交回复
热议问题