In C#, a const has to be initialized when it is declared. But, many times we put configuration details in XML files which the application needs to read once and not change for the life of the application. One can use “readonly” to achieve just this.

readonly fields can either be initialized at declaration or in a constructor. That's it. It cannot be modified anywhere else.


Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.