An online test has this question:
Features of Read Only Variable:
- It is allocated at compile time
- Declaration and initialization is separated
- It is allocated at runtime
- All of these
The test gave the answer as 4. I get 2 and 3 but not sure about 1. Would this be an example of when the answer of 1 could occur:
private readonly int readonlyExample = 10;
Note: I would normally use a const for the example above
These possible answers are a bit confusing (in my opinion).
What is actually going on is the C# compiler actually emits something like this:
Given that, #2 seems like a possible choice. The declaration and assignment are separated. (What they even mean by that is up for grabs)
3 is also possibly correct because the value has to live in memory somewhere. It isn’t a compile time constant.