Difference between const and readonly

The read only keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A read only field can be initialized either at the declaration or in a constructor. Therefore read only field can have different values depending on the constructor used. Also, while a const field is a compile time constant but the read only field can be used for run time constants.

Comments

Popular posts from this blog

When to use Truncate and Delete Command in SQL

Enable HTTP Transport Security (HSTS) in IIS 7

Difference Between Delete & Truncate in Sql Server