Define constants with const keywords : Const : Class C# Examples


C# Examples » Class » Const »

 

Define constants with const keywords






The const modifier is used to declare fields or local variables that cannot be changed.
These variables must be given initial values when they are declared.
const implies static.





    
using  System;

class  Constants
{
        public  const  int  value1  =  33;
        public  const  string  value2  =  "Hello";
}
class  MainClass
{
        public  static  void  Main()
        {
                Console.WriteLine("{0}  {1}",  
                Constants.value1,  
                Constants.value2);
        }
}
    
   
  
   



Output

33 Hello


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Const