using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ObjectTest
{
    class Rectangle
    {
        public double width, height;
        public Rectangle(double w, double h)
        {
            width = w;
            height = h;
        }
        public double area()
        {
            return width * height;
        }
        public void print()
        {
            Console.WriteLine("width=" + width + " height=" + height + " area()=" + area());
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Rectangle r = new Rectangle(5.0, 3.0);
            r.print();
            Rectangle r2 = new Rectangle(4.0, 6.0);
            r2.print();
        }
    }
}

文章轉載:陳鍾誠 (2011年10月04日),(網頁標題) 矩形物件,(網站標題) 免費電子書:C# 程式設計,2011年10月04日,取自 http://cs0.wikidot.com/rectangleobject ,網頁修改第 0 版。

arrow
arrow

    Johnson峰 發表在 痞客邦 留言(0) 人氣()