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

How does the clr work?

493


Can a struct have a default constructor (a constructor without parameters) or a destructor in c#?

507


Explain get and set accessor properties?

483


What is the meaning of extention?

474


What do you know about device context?

515






What is a dimensional array?

454


What is ienumerable <> in c#?

470


Why is c# good for games?

513


Which is faster dictionary or list?

526


What do you mean by expression tree?

436


What are the 2 broad classifications of data types available in c#?

458


Whats an assembly? Describe the importance of assembly?

489


Enlist the different types of classes in c#?

518


What are the advantages of using delegates in c#?

462


What is a multi line comment?

539