Use an access modifier with an accessor : public « Class « C# / CSharp Tutorial






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);  
  }  
}
Original value of ob.MyProp: 0
Value of ob.MyProp after increment: 1








7.17.public
7.17.1.Public vs private access
7.17.2.Use an access modifier with an accessor
7.17.3.Re-using Base Class Identifiers