0

What are the difference between Readonly instance fields and Static readonly fields ?

And how can we implement the Static readonly fields by Access Modifiers?

  • 1
    Possible duplicate of [Static vs non-static class members](http://stackoverflow.com/questions/9924223/static-vs-non-static-class-members). There are other questions on SO that answer your questions: [What are the benefits to marking a field as `readonly` in C#?](http://stackoverflow.com/questions/277010/what-are-the-benefits-to-marking-a-field-as-readonly-in-c) – Ed Chapel May 14 '14 at 06:38
  • 1
    The static one is static; that is the entire difference. And you "implement" it by adding a modifier... so... what exactly is the question? – Marc Gravell May 14 '14 at 06:39

1 Answers1

0

The main difference between Readonly instance fields and Static Readonly fields is that Readonly are evaluated when instance is created and Must have set value by the time constructor exits. whereas, Static readonly fields are evaluated when code execution hits class reference (i.e.: new instance is created or static method is executed) and Must have evaluated value by the time static constructor is done

Zeeshan
  • 2,535
  • 1
  • 22
  • 43