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

explain DIFFERENCE BETWEEN CLASS AND MODULE?

3 Answers  


1.write a program in C# to find a given point which is inside in a circle. Given circle's radius and its center point? 2.Write a program in C# to generated 20 prime numbers greater than a given number? (It should be more efficient for large numbers also) 3. Write a Code to check whether a given point is inside a circle or not? given Circle's raduis and its center point. 4. using oops concept, design an elevator do not forget buttons on each floor..

2 Answers  


Hi all,I am the beginner. Please tell use of finally block.

6 Answers   IBM,


How will U encapsulate button trigger event into text_box event of Pressing Enter key?i.e only after pressing Enter after the text is typed the button trigger event should activate?

6 Answers   TCS,


how to access the virtual method without creating the objet for the virtual method?

1 Answers  






Can you inherit multiple interfaces?

7 Answers   Mind Tree, Host4Big, Moftak Solutions,


What is the use of giving more than one CATCH BLOCK in one TRY block? Directly we can give that catch(Exception e)?Why we go for arrayoutofbound Exception,divided by zero etc..? Explain

2 Answers  


which datatype i have to use we i need dynamic size.for eg. empname .in first row it have only five chars.but next row it have 100 chars.

3 Answers  


How to navigate from one page(form) to another page(form) using C#.net...please give me the example

6 Answers  


Explain manifest & metadata?

5 Answers   IBM, Wipro,


What?s the advantage of using System.Text.StringBuilder over System.String?

3 Answers  


Does c# supports destructors?

9 Answers   Choice Solutions,






Categories