Declare class and use it : Class Definition : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Class Definition »

 

Declare class and use it









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
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; 
  } 
} 
  
public 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()); 
 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Class Definition