Use an access modifier with an accessor : Public : Class C# Examples


C# Examples » Class » Public »

 

Use an access modifier with an accessor









    
using  System;    
    
class  MySequence  {      
    int  prop;      
    
    public  MySequence()  {  prop  =  0;  }    
    
    public  int  MyProp  {    
        get  {    
            return  prop;    
        }    
        private  set  {  //  private    
            prop  =  value;    
        }      
    }    
  
    public  void  increaseSequence()  {  
        MyProp++;  
    }  
}      
  
class  MainClass  {      
    public  static  void  Main()  {      
        MySequence  ob  =  new  MySequence();    
    
        Console.WriteLine("Original  value  of  ob.MyProp:  "  +  ob.MyProp);    
    
        ob.increaseSequence();  
        Console.WriteLine("Value  of  ob.MyProp  after  increment:  "  
                                            +  ob.MyProp);    
    }    
}
    
   
  
   



Output

Original value of ob.MyProp: 0
Value of ob.MyProp after increment: 1


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Public