1. 程式人生 > >C#語法基礎-定義一個矩形物件

C#語法基礎-定義一個矩形物件

using System;
namespace RectangleApplication
{
    class Rectangle
    {
		double length;
		double width;
		
		public void accecptnum(){
			length=4.0;
			width=3.0;
		}
		
		public double getarea(){
			return length*width;
		}
		
		public void display(){
			Console.WriteLine("Length:{0}",length);
			Console.WriteLine("Width:{0}",width);
			Console.WriteLine("Area:{0}",getarea());
			
		}
		

    }
    
    class ExecuteRectangle
    {
        static void Main(string[] args)
        {
			Rectangle r = new Rectangle();
			r.accecptnum();
			r.display();
			Console.ReadLine();
        }
    }
}

執行結果: