Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# const vs readonly

A const is a compile-time constant whereas readonly allows a value to be calculated at run-time and/but be set in the constructor or field initializer. So, a 'const' is always known at compile time but 'readonly' is not necessarily known at compiletime, but once it is assigned nant be changed.
constant and readonly both are not midificable. constant has to be known at compiletime while readonly could be left to be assign once in runtime limetedly(initilizer/constructor but not every wher of the code you like) 
with some modification to original
https://learn.microsoft.com/en-us/archive/blogs/ericlippert/immutability-in-c-part-one-kinds-of-immutability
https://stackoverflow.com/questions/55984/what-is-the-difference-between-const-and-readonly-in-c#:~:text=A%20const%20is%20a%20compile,on%20different%20types%20of%20immutability.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #const #readonly
ADD COMMENT
Topic
Name
6+7 =