What is the difference between read-only and constants? | C# interview Questions 21

Read-Only:

Initialized at declaration or in the constructor.
Can have different values at runtime.
Constants:

Initialized at declaration.
Value is fixed and unchangeable.
Key Difference: Read-only can be set at runtime, while constants are set at compile-time and cannot change.

Leave a Reply

Your email address will not be published. Required fields are marked *