✅ readonly keyword vs const keyword and use-case
Hello guys, I just read a bit about the readonly keywords. From what I've read, using the
I read that using const means the value is determined at compile-time itself while using readonly means value is determined at run-time.
My first question concerning the
When we declare a property, consider the following:
My question is, if we omit the readonly keyword and just use { get; } without the set keyword, does the property behave as readonly?
Second question is, what are the use cases of readonly vs const keyword please
readonly keyword, we can only assign a particular value to a variable either at declaration level or when using the constructor. In constrast with the const keyword, I think we can only assign a value to it in the declaration part.I read that using const means the value is determined at compile-time itself while using readonly means value is determined at run-time.
My first question concerning the
readonly keyword:When we declare a property, consider the following:
My question is, if we omit the readonly keyword and just use { get; } without the set keyword, does the property behave as readonly?
Second question is, what are the use cases of readonly vs const keyword please