첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ 예제

using System;
using System.Collections.Generic;

#region 도형 출력하기 - PrintShape(shapeList)

/// <summary>
/// 도형 출력하기
/// </summary>
/// <param name="shapeList">도형 리스트</param>
private void PrintShape(List<Shape> shapeList)
{
    foreach(Shape shape in shapeList)
    {
        switch(shape)
        {
            case null :

                Console.WriteLine("NULL");

                break;

            case Circle circle :

                Console.WriteLine($"RADIUS={circle.Radius}");

                break;

            case Rectangle rectangle when rectangle.Width == rectangle.Height :

                Console.WriteLine($"SIZE={rectangle.Width}");

                break;

            case Rectangle rectangle :

                Console.WriteLine($"WIDTH={rectangle.Width},HEIGHT={rectangle.Height}");

                break;

            default : 

                Console.WriteLine(shape.ToString());

                break;
        }
    }
}

#endregion

/// <summary>
/// 도형
/// </summary>
public class Shape
{
}

/// <summary>
/// 원
/// </summary>
public class Circle : Shape
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Property
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 반경 - Radius

    /// <summary>
    /// 반경
    /// </summary>
    public double Radius { get; set; }

    #endregion
}

/// <summary>
/// 사각형
/// </summary>
public class Rectangle : Shape
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Property
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 너비 - Width

    /// <summary>
    /// 너비
    /// </summary>
    public double Width { get; set; }

    #endregion
    #region 높이 - Height

    /// <summary>
    /// 높이
    /// </summary>
    public double Height { get; set; }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요