What is the difference between Constant and ReadOnly? - ProProfs Discuss
Advertisement

What is the difference between Constant and ReadOnly?

Asked by T. Lopez, Last updated: Apr 05, 2024

+ Answer
Request
Question menu
Vote up Vote down

1 Answer

W. Wright

W. Wright

Let's see how far my knowledge stretches

W. Wright
W. Wright, Biology student, Biology student, Astoria

Answered Jun 13, 2019

Constant and ReadOnly are two important keywords in C# programming. They are used to declare variables, but the main difference between the two is the types of variables they declare. Constant is used to declare constant variables. Constant variables are values that need to be declared once during declaration before whatever computation they are being declared to do will start. Constant variables are assigned just once and they cannot be changed when the program is being executed. Readonly, on the other hand, is used to declare modifiable variables.

Constant and ReadOnly are two important keywords in C# programming. They are used to declare
Any variable declared with Readonly can be changed even when the program is being executed. Readonly can be used to declare variables during declaration i.e. before the running of the program, and it can be declared during runtime inside a constructor. Constant variables are represented in a code during declaration and they are static throughout the runtime, while Readonly is not static because it can be changed and they are stored in the memory.

upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.