What is the difference between const and static read-only?

What is the difference between const and static read-only?

The difference is that static read-only can be modified by the containing class, but const can never be modified and must be initialized to a compile time constant. To expand on the static read-only case .
The Constant Fields are those which cannot be changed in runtime. Its value has to be assigned at declaration time. const string strMyString="Constant Data" ; //This is valid.Once declared now the value cannot be reassigned strMyString="Changed Data" ...

By:kamal
Date:2013-10-10 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Links

C interview questions and answers for experienced and fresher