4 ms·
public static double ComputeArea(object shape) => shape switch { Square s => s.Side * s.Side, Circle c => c.Radius * c.Radius * Math.PI,
by derision 7y ago
public static double ComputeArea(object shape) =>
shape switch {
Square s => s.Side * s.Side,
Circle c => c.Radius * c.Radius * Math.PI,
Rectangle r => r.Height * r.Length,
_ => throw new ArgumentException( message: "shape is not recognized", paramName: nameof(shape));
}
- aar0nsa3nz 7y agoSorry, I couldn't figure out how to write a code block.
- derision 7y agoTwo spaces in front of each line