Readonly Fields : Readonly : Class C# Examples


C# Examples » Class » Readonly »

 

Readonly Fields









    
class  Color
{
        public  Color(int  red,  int  green,  int  blue)
        {
                this.red  =  red;
                this.green  =  green;
                this.blue  =  blue;
        }
        
        int  red;
        int  green;
        int  blue;
        
        public  static  readonly  Color  Red;
        public  static  readonly  Color  Green;
        public  static  readonly  Color  Blue;
        
        static  Color()
        {
                Red  =  new  Color(255,  0,  0);
                Green  =  new  Color(0,  255,  0);
                Blue  =  new  Color(0,  0,  255);
        }
}

class  MainClass
{
        static  void  Main()
        {
                Color  background  =  Color.Red;
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Readonly