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

TestProject.zip
0.00MB

▶ Shape.cs

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

 

728x90

 

▶ Line.cs

namespace TestProject
{
    /// <summary>
    /// 선
    /// </summary>
    public class Line : Shape
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region X1 - X1

        /// <summary>
        /// X1
        /// </summary>
        public double X1 { get; set; }

        #endregion
        #region Y1 - Y1

        /// <summary>
        /// Y1
        /// </summary>
        public double Y1 { get; set; }

        #endregion
        #region X2 - X2

        /// <summary>
        /// X2
        /// </summary>
        public double X2 { get; set; }

        #endregion
        #region Y2 - Y2

        /// <summary>
        /// Y2
        /// </summary>
        public double Y2 { get; set; }

        #endregion
    }
}

 

300x250

 

▶ Rectangle.cs

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

        #region X - X

        /// <summary>
        /// X
        /// </summary>
        public double X { get; set; }

        #endregion
        #region Y - Y

        /// <summary>
        /// Y
        /// </summary>
        public double Y { get; set; }

        #endregion
        #region 너비 - Width

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

        #endregion
        #region 높이 - Height

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

 

▶ Circle.cs

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

        #region X - X

        /// <summary>
        /// X
        /// </summary>
        public double X { get; set; }

        #endregion
        #region Y - Y

        /// <summary>
        /// Y
        /// </summary>
        public double Y { get; set; }

        #endregion
        #region 반지름 - Radius

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

        #endregion
    }
}

 

▶ Program.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            Rectangle rectangle = new Rectangle();

            rectangle.X      = 100;
            rectangle.Y      = 100;
            rectangle.Width  = 200;
            rectangle.Height = 100;

            double area = GetArea(rectangle);

            Console.WriteLine(area);
        }

        #endregion
        #region 영역 구하기 - GetArea(shape)

        /// <summary>
        /// 영역 구하기
        /// </summary>
        /// <param name="shape">도형</param>
        /// <returns>영역</returns>
        private static double GetArea(Shape shape)
        {
            double area = shape switch 
            {
                null        => 0,
                Line _      => 0,
                Rectangle r => r.Width * r.Height,
                Circle c    => Math.PI * c.Radius * c.Radius,
                _           => throw new ArgumentException()
            };

            return area;
        }

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

댓글을 달아 주세요