Encapsulation example : Class Definition : Class C# Examples


C# Examples » Class » Class Definition »

 

Encapsulation example









    
class  MyRectangle
{
      private  uint  width;
      private  uint  height;
      private  uint  area;

      public  uint  Width
      {
            get
            {
                  return  width;
            }

            set
            {
                  width  =  value;
                  ComputeArea();
            }
      }

      public  uint  Height
      {
            get
            {
                  return  height;
            }

            set
            {
                  height  =  value;
                  ComputeArea();
            }
      }

      public  uint  Area
      {
            get
            {
                  return  area;
            }
      }

      private  void  ComputeArea()
      {
            area  =  width  *  height;
      }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Class Definition