Home > DeveloperSection > Interviews > What is the difference between constants and read-only variables that are used in programs?

Posted on    September-02-2014 11:10 PM

 C# C# 
Ratings:
 1 Answer(s)
  710  View(s)
Rate this:

Sumit Kesarwani

Total Post:782

Points:3910
Posted on    September-02-2014 12:00 AM

Constants perform the same tasks as read-only variables with some differences. The differences between constants and read-only are

Constants:

Constants are dealt with at compile-time.

Constants supports value-type variables.

Constants should be used when it is very unlikely that the value will ever change.

Read-only:

Read-only variables are evaluated at runtime.

Read-only variables can hold reference type variables.

Read-only variables should be used when run-time calculation is required.


Don't want to miss updates? Please click the below button!

Follow MindStick