What's the difference between const and readonly ?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Will the name change be reflected in any of the existing .net framework 2.0 apis, assemblies, or namespaces?

786


What is the difference between model and entity?

733


I have 2+ years of fake experience,actually i could not answer for project questions..?how can i answer please suggest me..?

2878


What are Non Action methods in ASP.Net MVC?

821


What is viewbag?

814


What is objectcontext? : Entity framework

853


What are the benefits of .net framework?

771


Are there any parts of the .net framework 3.0 that only work on windows vista?

830


what is msl?

823


What is renderbody?

783


Why to use html.partial in mvc?

929


What are ajax helpers in asp.net mvc?

825


What is .net architecture and framework?

820


Is mvc 4 supporting windows azure sdk (software development kit) ?

780


What are the versions of .net framework?

767