C# const precedes the variable type.The value cannot be rewritten.What happens if the price cannot be changed?What does it mean?And what are the benefits?When do I need a const?c#
Described by the const keyword.
You must not create constants to represent information that is expected to change at any time. For example, do not use constant fields to store service prices, product version numbers, company brand names, etc. These values may change over time.
So I don't think you need to use it very much.
I don't think it's enough to vote negatively, but I don't think it's going to increase speed or efficiency.NET will compile JIT.This means that variables can be compiled by determining accessibility at runtime, so optimization occurs after detecting that they are not changed even if they are not const-specified.
The value is guaranteed to remain the same.
Enables you to build code based on that and optimizes based on that, increasing execution speed and execution efficiency
There are quite a few variables that should not be rewritten when developing in large groups.
Const is more for programmers than for compilers.
When I grep the source code of the oil, I use
DllImportdescribes the specifications of the external functions (such as fixed buffer size)
and so on.
For c#, you are unlikely to need to use
const to describe anything about the program itself.You can use it to describe "constants derived from something that already has specifications."
© 2022 OneMinuteCode. All rights reserved.