Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagec#
themeEmacs
title개선된 패턴매칭예-if문 단계를 줄일수있음
linenumberstrue
switch (message)
{
    case Cmd cmd:        
        break;
    case "snap":       
        break;
    case "print":        
        break;
}


switch (shape)
{
    case Square s when s.Side == 0:
    case Circle c when c.Radius == 0:
        return 0;

    case Square s:
        return s.Side * s.Side;
    case Circle c:
        return c.Radius * c.Radius * Math.PI;
    default:
        throw new ArgumentException(
            message: "shape is not a recognized shape",
            paramName: nameof(shape));
}


컴파일러 프로젝트내에서 업그레이드 : Install-Package Microsoft.Net.Compilers -Version 2.3.2

...