Define Rectangle class with method to compute the area : Member Method : Class C# Examples


C# Examples » Class » Member Method »

 

Define Rectangle class with method to compute the area









    
using  System;  
  
class  Rect  {  
    public  int  width;  
    public  int  height;  
  
    public  Rect(int  w,  int  h)  {  
        width  =  w;  
        height  =  h;  
    }  
  
    public  int  area()  {  
        return  width  *  height;  
    }  
}  
    
class  UseRect  {  
    public  static  void  Main()  {      
        Rect  r1  =  new  Rect(4,  5);  
        Rect  r2  =  new  Rect(7,  9);  
  
        Console.WriteLine("Area  of  r1:  "  +  r1.area());  
  
        Console.WriteLine("Area  of  r2:  "  +  r2.area());  
  
    }  
}
    
   
  
   



Output

Area of r1: 20
Area of r2: 63


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Member Method