What is the difference between readonly , const , and static ?
What is the difference between readonly, const, and static? Anubhav Sharma 404 19 Jun 2025 What is the difference between readonly, const, and static?
conststatic.Use when: Value is truly constant and known at compile time (like Pi, conversion factors, etc.)
readonlyUse when: Value should be set once at runtime (e.g., ID, creation timestamp).
staticUse when: You want a member that is shared across all instances (like configuration, counters, etc.)
Combined Usage
You can combine
staticwithreadonly:Means: shared across all instances, value set at runtime, but not modifiable afterward.
Summary Table
constreadonlystaticreadonly)