What is the difference between const and readonly in c#.net?
Answer / Leena Rani
In C#, both const and read-only variables are used to hold constant values, but there are some differences:
- const variables must be initialized at the time of declaration and their value cannot change. They are compiled into the assembly itself.
- readonly fields can be initialized either at the time of declaration or in the constructor. They are stored as fields within an object and can have different values for each instance.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is a clr host?
Why do I get an error (cs1006) when trying to declare a method without specifying a return type?
Is goto statement supported in C#? How about Java?
How many constructors can a class have c#?
What are get and set in c#?
how to cleanup object that does not support dispose method? How to implement dispose for such scenarios?
How can you overload a method?
Are arrays immutable c#?
Illustrate the differences between the system.array.copyto() and system.array.clone()?
Why do we use class in c#?
Define encapsulation?
Can datetime be null c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)