5
Reply

What is the difference between Static, Const and read only?

Jasbeer Singh

Jasbeer Singh

Dec 16, 2016
2.5k
1

    Const: Const is nothing but "constant", a variable of which the value is constant but at compile time. And it's mandatory to assign a value to it. By default a const is static and we cannot change the value of a const variable throughout the entire program.Readonly: Readonly is the keyword whose value we can change during runtime or we can assign it at run time but only through the non-static constructor. Not even a methodStatic ReadOnly: A Static Readonly type variable's value can be assigned at runtime or assigned at compile time and changed at runtime. But this variable's value can only be changed in the static constructor. And cannot be changed further. It can change only once at runtime

    Gnanavel Sekar
    February 20, 2017
    3

    The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used.

    Navdeep Singh
    March 30, 2017
    1

    Static is common to all Const means value is fixed Readonly is used to change value one time in construct er

    Mukesh Kumar
    September 05, 2017
    0

    Static is common to all Const means value is fixed Readonly is used to change value one time in construct er

    Mukesh Kumar
    September 05, 2017
    0

    static means the variable is common to all const means if we initialize variable first time then never be changed we have to initialize at the time of declearation.& readonly is changed one time in constructor. thanks

    Mukesh Kumar
    August 22, 2017
    0