Method in class

using System;
class Rectangle
{
    public int height;
    public int width;
    public void area()
    {
        Console.WriteLine("The area of the Rectangle is: " + height * width);
    }
}
using System;

class Program
{
    public static void Main(String[] args)
    {
        Rectangle rec = new Rectangle();
        rec.height = 10;
        rec.width = 5;
        rec.area();
    }
}

No comments:

Post a Comment