'Static readonly' vs. 'const'

前端 未结 18 3027
旧巷少年郎
旧巷少年郎 2020-11-22 04:07

I\'ve read around about const and static readonly fields. We have some classes which contain only constant values. They are used for various things

18条回答
  •  猫巷女王i
    2020-11-22 04:51

    Static Read Only:

    The value can be changed through a static constructor at runtime. But not through a member function.

    Constant:

    By default static. A value cannot be changed from anywhere (constructor, function, runtime, etc. nowhere).

    Read Only:

    The value can be changed through a constructor at runtime. But not through a member function.

    You can have a look at my repository: C# property types.

提交回复
热议问题