1. const Modifier
Initialization time:During compilation, the value has been embedded into the code during compilation;
Value status:Dynamic Modification not allowed
Modification Scope: Field, local variable
Main application scenarios: It is mainly used for variable values that do not need to be changed during the program running, such as the mathematical symbol PI;
2. static Modifier
Initialization time: During running, you can assign values when declaring them, or assign values when using constructors or constructors.
Value status: Allowed to be modified
Modification Scope: The class, field, attribute, method, operator, event, and constructor cannot be used for any type other than the indexer, destructor, or class)
Main application scenarios: Mainly applies to the public attributes of the class.
3. readonly Modifier
Initialization time: During runtime, you can assign values during declaration or assign values to constructors in the class.
Value status: Modification allowed, but can only be modified in the constructor
Modification Scope: Field
Main application scenarios: The read-only attribute of the instantiated object.
4. static readonly Modifier
Initialization time: The runtime is a combination of two keywords.
Value status: Modification allowed. Values are assigned during Declaration or in static constructors.
Modification Scope: Field
Main application scenarios: First, compared with const, it is mainly used for reference variables, while const can only be used for string-type reference variables. Second, the read-only public attribute of the class
This article is from the son of the Sea blog, please be sure to keep this source http://4769069.blog.51cto.com/4759069/1282498