Constants

Similar to, yet different from, read-only fields are constants. Constants aren’t fields but deserve treatment in this context because of their similar syntax and to point out some of the fundamental differences.

The goal of constants is to provide a way to give a symbolic name to values that are set in stone and will never ever change. Examples of constants include e (2.71828...) and pi (3.14159...). But, some things that seem constant deceptively are not. For example, although a tax percentage may remain the same for a long time, it isn’t constant.

For example, System.Math defines a couple of public constants:

public static class Math{    public const double PI = 3.1415926535897931;    public const double ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.