0 votes
by (2.5k points)
In C#, there is constants and read-only variables, what's the difference and when should I use each?

1 Answer

0 votes
by (2.5k points)
Constant variables are declared at compile time and have a value set at that point. Once the application is compiled, the value cannot be changed.

Read-only variables are set at runtime, but can be set only in their declaration *or* in a constructor. For this reason, you'll generally find that read-only variables have a value that should be "worked out" at runtime, whereas constants you would know the value ahead of time.
Welcome to .NET Q&A, where you can ask questions and receive answers from other members of the community.
...