Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between Readonly and const keyword in C#.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 158
    Comment on it

    Const keyword

    • Const variable in C# are compile time variable i.e value is known at compile time.
    • The assignment to const variable is only done at the time of declaration and this value of variable remain constant throughout lifetime of the program.
    • These variable are accessed via "Classname.Variablename".
    • Such variable can be declared and intialized in any method of class.

    Readonly keyword

    • Readonly is a keyword which when used with a variable then the value of that variable can only be changed either at runtime or at the time of the instance initialization.
    • The assignment to readonly variable is only done at the time of declaration or through constructor of the class.
    • These variable are accessed via "Instancename.Variablename".
    • Readonly keyword cannot be used with variables in the methods even the value of readonly variable cannot be changed in any method of the class.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: