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 17 Classesprevious at this levelnext at this level 17.4 Fieldsprevious at this levelnext at this level 17.4.2 Readonly fieldsprevious at this levelnext at this level 17.4.2.1 Using static readonly fields for constants Paragraph 11 A static readonly field is useful when a symbolic name for a constant value is desired, but when the type of the value is not permitted in a const declaration, or when the value cannot be computed at compile-time. [Example: In the example
public class Color  
{  
   public static readonly Color Black = new Color(0, 0, 0);  
   public static readonly Color White = new Color(255, 255, 255);  
   public static readonly Color Red = new Color(255, 0, 0);  
   public static readonly Color Green = new Color(0, 255, 0);  
   public static readonly Color Blue = new Color(0, 0, 255);  
   private byte red, green, blue;  
   public Color(byte r, byte g, byte b) {  
      red = r;  
      green = g;  
      blue = b;  
   }  
}  
the Black, White, Red, Green, and Blue members cannot be declared as const members because their values cannot be computed at compile-time. However, declaring them static readonly instead has much the same effect. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS