What's the difference between const and readonly ?

Answers were Sorted based on User's Feedback



What's the difference between const and readonly ?..

Answer / kirti

You can initialize readonly variables to some runtime values. Let's say your program uses current date and time as one of the values that won't change. This way you declare public readonly string DateT = new DateTime().ToString().

Is This Answer Correct ?    0 Yes 0 No

What's the difference between const and readonly ?..

Answer / mr vinod kumar

The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants as in the following example:
public static readonly uint l1 = (uint) DateTime.Now.Ticks;
What does a character do ?
On most systems, produces a rather annoying beep.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net Framework Interview Questions

What are action filters?

0 Answers  


Can we add constraints to the route? If yes, explain how we can do it?

0 Answers  


What is NonActionAttribute ?

0 Answers   Cognizant,


if u add an import stmt to an application u can do the same by adding reference to the apllication then what is the diff bet these two ?

1 Answers  


How do you register the dotnet component or assembly ?

1 Answers   Accenture, BirlaSoft,






What does assert() method do?

1 Answers   MCN Solutions, Siebel Systems,


what is an assembly?

11 Answers  


I am going for H1B visa interview, I am not having bank statement ,is it neccesary for stamping process? how to handle the,consulate people without that statement ?

2 Answers  


what is Framework?

3 Answers  


Explain what is asp.net mvc?

0 Answers  


How can you return string result from Action in ASP.Net MVC?

0 Answers  


How do you initiate a string without escaping each backslash ?

1 Answers  


Categories