Jasbeer Singh
What is the difference between Static, Const and read only?
By Jasbeer Singh in .NET on Dec 16 2016
  • Gnanavel Sekar
    Feb, 2017 20

    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

    • 4
  • Navdeep Singh
    Mar, 2017 30

    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.

    • 1
  • Mukesh Kumar
    Aug, 2017 22

    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

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS