Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0101 A demo method

The following code adds a method to class Rectangle. It calculates the area of the rectangle. using System; class Rectangle{ public int Width; public int Height; public int GetArea(){ return Width * Height; } } class Program { static void Main(string[] args) { Rectangle r = new Rectangle(); r.Width = 5; r.Height = 6; Console.WriteLine(r.GetArea()); } } The output: 30