Qus:    Differentiate between constants and read-only variables.
Oct 22, 2020 08:37 2 Answers Views: 105 RITA
Prev Next
Answers (2)
ANANYA Oct 23, 2020 02:35
Answer:   Constants
Evaluated at compile time
Support only value type variables
They are used when the value is not changing at compile time
Cannot be initialized at the time of declaration or in a constructor

Read-only Variables
Evaluated at run-time
They can hold the reference type variables
Used when the actual value is unknown before the run-time
Can be initialized at the time of declaration or in a constructor

PARTH Oct 23, 2020 08:26
Answer:   1) const fields has to be initialized while declaration only, while readonly fields can be initialized at declaration or in the constructor.
2) const variables can declared in methods ,while readonly fields cannot be declared in methods.
3) const fields cannot be used with static modifier, while readonly fields can be used with static modifier.
4) A const field is a compile-time constant, the readonly field can be used for run time constants.

Post Your Answer
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect