2 ms·
just FYI, the C# can be rewritten as a switch expression which is more comparable to the scala return shape switch { Sq
by keithnz 7y ago
just FYI, the C# can be rewritten as a switch expression which is more comparable to the scala
return shape switch
{
Square s when s.Side == 0 => 0,
Circle c when c.Radius == 0 => 0,
Triangle t when t.Base == 0 || t.Height == 0 => 0,
Rectangle r when r.Length == 0 || r.Height == 0 => 0,
Square s => (s.Side * s.Side),
Circle c => (c.Radius * c.Radius * Math.PI),
Triangle t => (t.Base * t.Height / 2),
Rectangle r => (r.Length * r.Height),
_ => throw new ArgumentException(message: "shape is not a recognized shape", paramName: nameof(shape))
};