Better HN
topnewbestaskshowjobs
Log inSign up

aar0nsa3nz

11 karma · joined Jun 27, 2019 (7y ago) · 2 submissions

Submissions

comment 6y ago · link · parent

Sorry, I couldn't figure out how to write a code block.

comment 6y ago · link · parent

With C# 8 you can also write it as:

  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))
    };