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

■ 배열을 병합하는 방법을 보여준다.

 

▶ 배열 병합하기 예제 (C#)

int[] sourceArray1 = { 1, 2, 3, 4, 5, 6 };
int[] sourceArray2 = { 3, 4, 5, 6, 7, 8 };

int[] targetArray = Merge(sourceArray1, sourceArray2);

foreach(int target in targetArray)
{
    Console.WriteLine(target);
}

 

▶ 배열 병합하기 (C#)

#region 병합하기 - Merge<TElement>(sourceArray1, sourceArray2)

/// <summary>
/// 병합하기
/// </summary>
/// <typeparam name="TElement">요소 타입</typeparam>
/// <param name="sourceArray1">소스 배열 1</param>
/// <param name="sourceArray2">소스 배열 2</param>
/// <returns>병합 배열</returns>
public TElement[] Merge<TElement>(TElement[] sourceArray1, TElement[] sourceArray2)
{
    TElement[] targetArray = new TElement[sourceArray1.Length + sourceArray2.Length];

    int index = 0;

    for(int i = 0; i < sourceArray1.Length; i++)
    {
        targetArray[index++] = sourceArray1[i];
    }

    for(int j = 0; j < sourceArray2.Length; j++)
    {
        targetArray[index++] = sourceArray2[j];
    }

    return targetArray;
}

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