⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c7-04.cs

📁 一本很好的教材.C#开发者必备.内容全面,很难得哦.
💻 CS
字号:
// 构造函数的第三个示例
using System;
abstract class Shape 
{
   public const double pi = Math.PI;
   protected double x, y, z;
   public Shape (double x, double y, double z) 
   {
      this.x = x;
      this.y = y;
      this.z = z;
   }
   public abstract double Area();
}
class Circle: Shape 
{
   public Circle(double radius): base(radius,0,0) 
   {
   }   
   public override double Area()
   { 
      return pi*x*x; 
   }
}
class Cylinder: Circle 
{
   public Cylinder(double radius, double height): base(radius)
   {
      y = height;
   }
   public override double Area() 
   {
      return 2*(base.Area()) + 2*pi*x*y; 
   }
}
class TestClass 
{
   public static void Main()  
   {
      double radius = 2.5, height = 3.0;
      Circle myCircle = new Circle(radius);
      Cylinder myCylinder = new Cylinder(radius, height);

      Console.WriteLine("圆的面积 = {0:F2}", 
                           myCircle.Area());
      Console.WriteLine("圆柱的面积 = {0:F2}",
                           myCylinder.Area());
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -