What is the difference between readonly and const

Answer Posted / sabina

both meant for constant values. a const field can only be
initialized at the declaretion of the field. a read only
field can be initialized either in initialization or in
constructer. therefore , reaadonly field can have different
values depending on the constructure used

also a const field is compile time constant , readonly
field can be used for runtime constants

Is This Answer Correct ?    18 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we need to call CG.SupressFinalize?

558


What is difference between singleton and static class in c#?

484


What is c sharp language?

518


What is routing in c#?

472


What are the collection types can be used in c#?

474






What is the console on a mac?

483


What does writeline mean?

534


What are Regex / regular expressions ?

603


What is linq c#?

508


Why do I get a security exception when I try to run my c# app?

552


Is c# used for frontend or backend?

592


What is the use of nullable types in c#?

492


Is int reference type c#?

509


Name the connections does microsoft sql server support?

490


How do you remove white spaces from a string?

503