Samir Bhogayta
What’s the difference between const and readonly?
By Samir Bhogayta in C# on Jun 25 2016
  • Mukesh Kumar
    Aug, 2017 31

    Const has fixed value You have intialise same time

    • 0
  • Samir Bhogayta
    Jun, 2016 25

    Readonly fields are delayed initalized constants. However they have one more thing different is that; When we declare a field as const it is treated as a static field. where as the Readonly fields are treated as normal class variables.const keyword used ,when u want's value constant at compile time but in case of readonly ,value constant at run timeForm the use point of view if we want a field that can have differnet values between differnet objects of same class, however the value of the field should not change for the life span of object; We should choose the Read Only fields rather than constants.Since the constants have the same value accross all the objects of the same class; they are treated as static.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS