Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 8 Language Overviewprevious at this levelnext at this level 8.7 Classesprevious at this levelnext at this level 8.7.1 ConstantsA constant is a class member that represents a constant value: a value that can be computed at compile-time. Constants are permitted to depend on other constants within the same program as long as there are no circular dependencies. The rules governing constant expressions are defined in §14.15. The example
class Constants  
{  
   public const int A = 1;  
   public const int B = A + 1;  
}  
shows a class named Constants that has two public constants.
Even though constants are considered static members, a constant declaration neither requires nor allows the modifier static. Constants can be accessed through the class, as in
using System;  
class Test  
{  
   static void Main() {  
      Console.WriteLine("{0}, {1}", Constants.A, Constants.B);  
   }  
}  
which prints out the values of Constants.A and Constants.B, respectively.
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS