What is the difference between readonly and const




Answers were Sorted based on User's Feedback



What is the difference between readonly and const..

Answer / 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

What is the difference between readonly and const..

Answer / 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

What is the difference between readonly and const..

Answer / vishnu

a read only
field can be initialized either in initialization or in
constructor

Is This Answer Correct ?    0 Yes 0 No




What is the difference between readonly and const..

Answer / porchelvi.a

Constant:
--------
we have to initialize at the declaration itself
we could not change the value of constant variable.

Read only:
----------
we can not initialize the Read only variable during
declaration.we can initialize it in constructor only.after
that we could not change the value.Read noly is instance
based variable.

Is This Answer Correct ?    1 Yes 3 No

Post New Answer



More C Sharp Interview Questions

If all code is written in a try block and write a catch block with Exception type Exception .In that scenario will all the exceptions catched by that catch block? or any exceptions which will not be caught?

3 Answers   Honeywell,


What is use of super class

4 Answers   NIIT,


What is overloading and how can this be done ?

4 Answers   MMTS,


How?s the DLL Hell problem solved in .NET?

3 Answers  


C# is case sensitive, what is mean by case sensitive

3 Answers  






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

2 Answers   Intel, Visual Soft,


What are the collection classes ?

2 Answers   Digital GlobalSoft,


What are anonymous methods ? why these methods are used and in what condition these methods are useful ?

1 Answers  


What are Generics?

5 Answers   TCS,


what is satelite assembly?

5 Answers   ABC,


Difference between multi-level and multiple inheritance?

4 Answers   Microsoft,


What is Abstraction?

7 Answers   Google, HCL, IBM, MAHINDRA, Tech Mahindra,






Categories