Changes

Jump to: navigation, search

C Sharp Variables and Constants

1 byte added, 16:26, 14 January 2008
What is a C# Constant?
== What is a C# Constant? ==
A constant is similar to a variable in that it provide provides a named location in memory to store a data value. Constants differ in one significant way in that once a value has been assigned to constant it cannot subsequently be changed.
Constants are particularly useful if there is a value which is used repeatedly throughout the application code. Rather than use the value each time, it makes the code easier to read if the value is first assigned to a constant and which is then referenced in the code. For example, it might not be clear to someone reading your C# code why you used the value 5 in an expression. If, instead of the value 5, you use a constant named ''interestRate'' the purpose of the value becomes much clearer. Constants also have the advantage that the if the programmer needs to change a widely used value it only needs to be changed once in the constant declaration and not each time it is referenced.

Navigation menu