圆柱继承圆, 属性分析数据合理性 C#
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace Circle
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Cylinder cylinder = new Cylinder();
- cylinder.R = 10;
- cylinder.H = 100;
- Console.WriteLine("Volueme:{0}",cylinder.Volume());
-
- Cylinder c1 = new Cylinder();
-
- c1.R = -10;
- c1.H = -100;
- }
- }
- class Circle
- {
- protected double r;
- public double R
- {
- get
- {
- return r;
- }
- set
- {
- if(value <= 0)
- throw new ArgumentOutOfRangeException("value,测试输入非法值给出的提示");
- else
- r = value;
- }
- }
- public double Area()
- {
- return Math.PI * r * r;
- }
- }
- class Cylinder:Circle
- {
- private double h;
- public double H
- {
- get
- {
- return h;
- }
- set
- {
- if (value <= 0)
- throw new ArgumentOutOfRangeException("value");
- else
- h = value;
- }
- }
- public double Volume()
- {
- return Area() * h;
- }
- }
-
- }