Read-Only fields can only be assigned values during initialization or in constructors. The static readonly field is very similar to the const field. The difference between them is that C # compiler does not compile the value of this static fieldCode(The const value is directly compiled into the code during compilation), but is dynamically parsed at each Runtime (just like treating a common variable ). That is to say, the value of the const field has been determined at compilation, and the value of the static readonly field is determined at runtime.
Constants must be initialized during declaration.
You can declare a field as static, indicating that the field is a class attribute rather than an object attribute. This allows the caller to use fields through the class at any time, even if the class does not have any instances.
Note: static classes and class members are used to create class instances to access data and functions. Static class members can be used to separate data and behavior independent of any object representation: No matter what changes occur to the object, these data and functions will not change accordingly. When the class does not depend on the data and behavior represented by objects, you can use static classes.