readonly vs const c#
readonly keyword is used to define a variable
which can be assigned once after declaration
either during declaration or in constructor.
const keyword is used to define a constant to be used in the program.
readonly vs const c#
readonly keyword is used to define a variable
which can be assigned once after declaration
either during declaration or in constructor.
const keyword is used to define a constant to be used in the program.
c# const vs readonly
A const is a compile-time constant whereas readonly allows a value to be calculated at run-time and set in the constructor or field initializer. So, a 'const' is always constant but 'readonly' is read-only once it is assigned.
Eric Lippert of the C# team has more information on different types of immutability.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us