-
Notifications
You must be signed in to change notification settings - Fork 56
/
Program.cs
38 lines (34 loc) · 996 Bytes
/
Program.cs
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
28
29
30
31
32
33
34
35
36
37
38
using System;
namespace Deconstruction
{
class Program
{
static void Main()
{
var s = new Size(10, 20);
Console.WriteLine(DiagonalLength(s));
Console.WriteLine(DescribeSize(s));
Console.WriteLine(Describe(s));
}
static double DiagonalLength(Size s)
{
(double w, double h) = s;
return Math.Sqrt(w * w + h * h);
}
static string DescribeSize(Size s) => s switch
{
(0, 0) => "Empty",
(0, _) => "Extremely narrow",
(double w, 0) => $"Extremely short, and this wide: {w}",
_ => "Normal"
};
static string Describe(object o) => o switch
{
Size(0, 0) => "Empty",
Size(0, _) => "Extremely narrow",
Size(double w, 0) => $"Extremely short, and this wide: {w}",
Size _ => "Normal shape",
_ => "Not a shape"
};
}
}