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

What is the use of getcommandlineargs() method in c#.net?

0 Answers  


What is a private constructor? where will you use it?

6 Answers   Fulcrum Logic,


Can you create an instance of a static class?

0 Answers  


What is multidimensional array in c#?

0 Answers  


What is the difference between Java and .NET garbage collectors?

0 Answers   BirlaSoft,






What?s the difference between the System.Array.CopyTo() and System.Array.Clone()?

3 Answers  


Can delegates be used as callbacks?

0 Answers  


What is the usage of transponders?

0 Answers   Wipro,


Explain the features of an abstract class in net.

0 Answers  


What is sqldataadapter in c#?

0 Answers  


What are custom exceptions? Why do we need them?

0 Answers  


Can we inherit singleton class in c#?

0 Answers  


Categories