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

To allow an element to be accessed using a unique key which .NET collection class is used ?

621


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

492


What is threading in c# with example?

461


Why c# is called type safe language?

465


What is callback function in c#?

531






What is thread in c#?

549


Why we use get set property in c#?

476


Is c# difficult to learn?

487


What problem does Delegate Solve?

568


Why do canadians say zed?

526


Why generics are used in c#?

492


How main method is called in c#?

517


What Is A Satellite Assembly?

543


Does c# support a variable number of arguments?

614


Can hashset contain duplicates c#?

470