What is the difference between readonly and const

Answer Posted / chandan kumar

The read only keyword is different from the const keyword. A
const field can only be initialized at the declaration of
the field. A read only field can be initialized either at
the declaration or in a constructor. Therefore, read only
fields can have different values depending on the
constructor used. Also, while a const field is a
compile-time constant, the read only field can be used for
runtime constants as in the

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the access modifiers in c#?

692


Why attributes are used in c#?

651


What is a factory in c#?

682


Can abstract class have parameterized constructor?

697


What is the use of private constructor in c#?

672


What is a hash table in c#?

721


What is the difference between // comments, /* */ comments and /// comments?

674


Is overriding of a function possible in the same class?

693


What is the difference between “constant” and “readonly” variables in c#?

738


Define an abstract class?

689


How do I create a multi language, multi file assembly?

838


How to move to a state-related codebase?

1193


how background thread access to ui control?

791


What does using do in c#?

692


What is the name of c# compiler?

855