What do you mean by const modifier in C# programming language?

 Posted by Goud.Kv on 9/3/2014 | Category: C# Interview questions | Views: 401 | Points: 40
Answer:

It is used to declare constants which cannot be modified. In C#, mostly we declare the const for numeric types, value types, strings etc.
Only way to modify a constant field is to do that at compile time only as const keyword restricts the field from being modified in the runtime.

Example,
const string Site = "DotNetFunda"; // Declaration of constant field

Site = "ITFunda"; // Compile time error


Asked In: Spotted While Learning | Alert Moderator 

Comments or Responses

Login to post response