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

What is the difference between Constant and ReadOnly?

What is the difference between Constant and ReadOnly?

Change Image    Delete

Asked by T. Lopez, Last updated: Nov 09, 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