WHAT ARE THE DIFFERENCE BETWEEN CONST AND READONLY?

Sumit Kesarwani

Total Post:782

Points:3910
Posted by  Sumit Kesarwani
C# 
C#
 1263  View(s)
Ratings:
Rate this:
  1. Sumit Kesarwani

    Post:782

    Points:3910
    What are the difference between const and readonly?

    A const can not be static, while readonly can be static.

    A const need to be declared and initialized at declaration only, while a readonly can be initialized at declaration or by the code in the constructor.

    A const’s value is evaluated at design time, while a readonly’s value is evaluated at runtime.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!