Jan 29, 2010

Readonly Fields in C# classes

- whose value shouldnot be changed as "Const" but where the value is not known until runtime.
- "Const" fields are internally static, but we need to declare as static for "Readonly" fields.
- Readonly fields are constants and also allow to do some calculations to determine the initial value of the fields, but const fileds are not.
- We can assign values to Readonly fields in constructors only not anywhere else.

3 comments:

  1. Gool link to learn about Readonly fields,constants...

    http://en.csharp-online.net/const,_static_and_readonly

    ReplyDelete
  2. Readonly fields can be initialized either at initialization or in constructor...

    ReplyDelete
  3. initialization means at the time of declaration

    ReplyDelete