C # contains two constants: static constants and Dynamic Constants. Proper exploitation can improve the program efficiency. Improper exploitation can increase the overhead and even cause errors.
Static constant: const (implicitly static)
For example, public const int compiledata = 1;
Dynamic constant: static readonly
For example, public static readonly runtimedate = 1;
Static constants are replaced with corresponding values during compilation, which is equivalent
Int value = compiledate;
Int compiledata = 1;
Static constants do not consume memory, but only support native data types.
Dynamic Constants are obtained at runtime, so the following statement is correct:
Public static readonly Hello = new Hello ();
Therefore, dynamic constants have greater flexibility, but they need to be saved. Therefore, memory consumption occurs and any type of constants is supported.
These are some tips of the monks. Please add and correct them.