[국원고 프로젝트] Utils Class(2)

Benedictus Park·2022년 12월 15일
0
post-thumbnail

namespace Utils
{
    public static class StringArrayExtension
    {
        public static T[] Append<T>(this T[] a, T[] b)
        {
            T[] result = new T[a.Length + b.Length];

            for(int i = 0; i < a.Length; i++)
            {
                result[i] = a[i];
            }
            for(int i = a.Length; i < a.Length + b.Length; i++)
            {
                result[i] = b[i - a.Length];
            }

            return result;
        }

        public static T[] Append<T>(this T[] a, T b)
        {
            T[] result = new T[a.Length + 1];

            for(int i = 0; i < a.Length; i++)
            {
                result[i] = a[i];
            }

            result[a.Length] = b;

            return result;
        }
    }
}
  • 모든 형태의 배열에 .Append 확장 메서드를 추가하는 방향으로 코드를 다시 작성하였다.

0개의 댓글