/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/programming-guide/classes-and-structs/snippets/instance-constructors/shapes/Program.cs
50 строк
1017 B
Tom Dykstra
Update snippets for NRT (#28622)
11 мар 2022, 19:03
Не верифицирован
11 мар 2022, 19:03
13fe3ed
Код
Авторство
О чём код?
abstract class Shape { public const double pi = Math.PI; protected double x, y; public Shape(double x, double y) { this.x = x; this.y = y; } public abstract double Area(); } class Circle : Shape { public Circle(double radius) : base(radius, 0) { } public override double Area() => pi * x * x; } class Cylinder : Circle { public Cylinder(double radius, double height) : base(radius) { y = height; } public override double Area() => (2 * base.Area()) + (2 * pi * x * y); } class Example { static void Main() { double radius = 2.5; double height = 3.0; var ring = new Circle(radius); Console.WriteLine($"Area of the circle = {ring.Area():F2}"); // Output: Area of the circle = 19.63 var tube = new Cylinder(radius, height); Console.WriteLine($"Area of the cylinder = {tube.Area():F2}"); // Output: Area of the cylinder = 86.39 } }