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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.