forked from domn1995/dunet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
27 lines (21 loc) · 765 Bytes
/
Program.cs
File metadata and controls
27 lines (21 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using Dunet;
using static Shape;
var circle = new Circle(10);
var rectangle = new Rectangle(10, 10);
var triangle = new Triangle(10, 10);
Console.WriteLine($"Circle area: {GetArea(circle)}");
Console.WriteLine($"Rectangle area: {GetArea(rectangle)}");
Console.WriteLine($"Triangle area: {GetArea(triangle)}");
static double GetArea(Shape shape) =>
shape.Match(
static circle => Math.PI * circle.Radius * circle.Radius,
static rectangle => rectangle.Length * rectangle.Width,
static triangle => triangle.Base * triangle.Height / 2
);
[Union]
partial record Shape
{
partial record Circle(double Radius);
partial record Rectangle(double Length, double Width);
partial record Triangle(double Base, double Height);
}