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

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

namespace Utils
{
    public static class ArrayAppender
    {
        public static void Append<T>(ref 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];
            }

            a = result;
        }

        public static void Append<T>(ref 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;
            a = result;
        }
    }
}
  • CallByReference를 사용하는 방향으로 코드를 다시 작성하였다.

0개의 댓글