当前位置:首页 > C#教程 > C#进阶

C#基本语法

using System;

namespace RectangleApplication {

   class Rectangle {
      // member variables
      double length;
      double width;

      public void Acceptdetails() {
         length = 4.5;    
         width = 3.5;
      }

      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.Acceptdetails();
         r.Display();
         Console.ReadLine(); 
      }
   }
}

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!