Which of the following statement is true about given Code?
public class Test
public readonly int x = 90;
public readonly int z;
public Test(int r)
z = r;
x = z + 1;
Code will be compiled successfully.
Error, read-only variable should be initialized either during declaration or in constructor .
Error, we can not assign the data to the read-only variables while declaring the variable .
Error, we can not assign the data to the read-only variables in constructor.
A read-only variable is a run time constant. we can assign the data to the read-only variable directly while declaring the variable or we can assign the data to the read-only variable in the constructor also.
Back To Top