첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Triangle.cs

namespace TestProject
{
    /// <summary>
    /// 삼각형
    /// </summary>
    public struct Triangle
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region Field

        /// <summary>
        /// 길이 1
        /// </summary>
        public int Length1;
        
        /// <summary>
        /// 길이 2
        /// </summary>
        public int Length2;
        
        /// <summary>
        /// 길이 3
        /// </summary>
        public int Length3;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 둘레 - Perimeter

        /// <summary>
        /// 둘레
        /// </summary>
        public readonly int Perimeter => Length1 + Length2 + Length3;

        #endregion
        #region 등변 여부 - IsEquilateral

        /// <summary>
        /// 등변 여부
        /// </summary>
        public readonly bool IsEquilateral => Length1 == Length2 && Length2 == Length3;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - Triangle(length1, length2, length3)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="length1">길이 1</param>
        /// <param name="length2">길이 2</param>
        /// <param name="length3">길이 3</param>
        public Triangle(int length1, int length2, int length3)
        {
            Length1 = length1;
            Length2 = length2;
            Length3 = length3;
        }

        #endregion
    }
}

 

728x90

 

▶ Program.cs

using System;

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

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

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            Triangle triangle = new Triangle(3, 4, 5);

            Print(triangle);
        }

        #endregion
        #region 출력하기 - Print(triangle)

        /// <summary>
        /// 출력하기
        /// </summary>
        /// <param name="triangle">삼각형</param>
        private static void Print(in Triangle triangle)
        {
            int  perimeter     = triangle.Perimeter;
            bool isEquilateral = triangle.IsEquilateral;

            Console.WriteLine($"{perimeter}, {isEquilateral}");
        }

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

댓글을 달아 주세요