'Static readonly' vs. 'const'

前端 未结 18 2910
旧巷少年郎
旧巷少年郎 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条回答
  •  执笔经年
    2020-11-22 04:54

    const:

    1. value should be given upon declaration
    2. compile time constant

    readonly:

    1. value can be given upon declaration or during runtime using constructors.The value may vary depend upon the constructor used.
    2. run time constant

提交回复
热议问题