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

TestProject.zip
다운로드

▶ ComparisonExtension.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 비교 확장
    /// </summary>
    public static class ComparisonExtension
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 작은 값 여부 구하기 - IsSmallerThan<TSource, TTarget>(source, target)

        /// <summary>
        /// 작은 값 여부 구하기
        /// </summary>
        /// <typeparam name="TSource">소스 타입</typeparam>
        /// <typeparam name="TTarget">타겟 타입</typeparam>
        /// <param name="source">소스 값</param>
        /// <param name="target">타겟 값</param>
        /// <returns>작은 값 여부</returns>
        public static bool IsSmallerThan<TSource, TTarget>(this TSource source, TTarget target)
            where TSource : struct, IComparable, IComparable<TSource>, IConvertible, IEquatable<TSource>, IFormattable
            where TTarget : struct, IComparable, IComparable<TTarget>, IConvertible, IEquatable<TTarget>, IFormattable
        {
            return Convert.ToDouble(source) < Convert.ToDouble(target);
        }

        #endregion
        #region 큰 값 여부 구하기 - IsLargerThan<TSource, TTarget>(source, target)

        /// <summary>
        /// 큰 값 여부 구하기
        /// </summary>
        /// <typeparam name="TSource">소스 타입</typeparam>
        /// <typeparam name="TTarget">타겟 타입</typeparam>
        /// <param name="source">소스 값</param>
        /// <param name="target">타겟 값</param>
        /// <returns>큰 값 여부</returns>
        public static bool IsLargerThan<TSource, TTarget>(this TSource source, TTarget target)
            where TSource : struct, IComparable, IComparable<TSource>, IConvertible, IEquatable<TSource>, IFormattable
            where TTarget : struct, IComparable, IComparable<TTarget>, IConvertible, IEquatable<TTarget>, IFormattable
        {
            return Convert.ToDouble(source) > Convert.ToDouble(target);
        }

        #endregion
    }
}

 

728x90

 

▶ Program.cs

using System;

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

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

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            int source = 20;
            int target = 25;

            Console.WriteLine(source.IsSmallerThan(target));
            Console.WriteLine(source.IsLargerThan(target));
        }

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

댓글을 달아 주세요