CSharp - Will the code compile: readonly field

Question

Will the code compile

class ReadOnlyEx
{
    public static readonly int staticReadOnlyValue;
    static ReadOnlyEx()
    {
        staticReadOnlyValue = 25;
    }
    //Some other code e.g. Main Method() etc..
}


Click to view the answer

Yes.

Note

We can assign a value to a readonly field during the declaration or through a constructor.