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

what is entity data model?

820


What are the benefits of .net framework?

779


What are the components of the .net framework.

813


What are ajax helpers in mvc?

751


What is viewbag title?

724


How to enable Attribute Routing?

882


What is RouteConfig.cs in ASP.Net MVC 4?

828


how do you mark a property as required? For example, for a project, the name is a required field.

831


What is the "helperpage.isajax" property?

920


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

1032


Explain what is the difference between view and partial view?

852


I want to fetch data from datareader. i have three tables in datareader. i want to bind my two table with datagrid, then i want to fetch a value from my third table. do u have any idea pls help me. we use dr.nextresult() for multiple tables.

2415


What is a view engine?

795


What is the difference between .net core and .net framework?

762


What are the advantages of razor view engine?

732