O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required