Will the code compile
class ReadOnlyEx { public readonly int nonStaticReadOnlyValue; public ReadOnlyEx(int x) { nonStaticReadOnlyValue = x; } //Some other code e.g.Main method() etc.. }
Yes.
We can assign a value to a readonly field during the declaration or through a constructor.