C#初始化基类

using System;

namespace RectangleApplication {

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

      public Rectangle(double l, double w) {
         length = l;
         width = w;
      }

      public double GetArea() {
         return length * width;
      }

      public void Display() {
         Console.WriteLine(Length: {0}, length);
         Console.WriteLine(Width: {0}, width);
         Console.WriteLine(Area: {0}, GetArea());
      }
   }//end class Rectangle  

   class Tabletop : Rectangle {
      private double cost;
      public Tabletop(double l, double w) : base(l, w) { }

      public double GetCost() {
         double cost;
         cost = GetArea() * 70;
         return cost;
      }

      public void Display() {
         base.Display();
         Console.WriteLine(Cost: {0}, GetCost());
      }
   }

   class ExecuteRectangle {

      static void Main(string[] args) {
         Tabletop t = new Tabletop(4.5, 7.5);
         t.Display();
         Console.ReadLine();
      }
   }
}

相关文章

c#如何实现添加到列表代码:var list = new&...
c#循环访问字典代码:foreach(var item in m...
using System; namespace OperatorsAppl { class Program ...
using System; class Program { static void Main(string[...
using System; namespace OperatorsAppl { class Program {...
using System; namespace DeclaringConstants { class Pro...