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

Name a few different return types of a controller action method?

0 Answers  


What are the different types of filters, in an asp.net mvc application?

1 Answers   NA,


What is mapping in entity framework? : Entity framework

0 Answers  


What are Code Blocks in Views?

0 Answers  


What are the advantages of asp.net mvc?

0 Answers  


what is Assemble

4 Answers   Microsoft,


What is session state management?

0 Answers  


What is the "helperpage.isajax" property?

0 Answers  


How does �side by side� work for the .net framework 3.0?

0 Answers  


Speaking of Boolean data types, what's different between C# and C/C++ ?

1 Answers  


Is the following route definition a valid route definition? {controller}{action}/{id}

0 Answers   NA,


What is the difference between managed and unmanaged code?

12 Answers   IBM,


Categories