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

TestProject.zip
0.00MB

▶ Program.cs

namespace TestProject;

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

    #region 바이트 배열 병합하기 - Merge(sourceArrayArray)

    /// <summary>
    /// 바이트 배열 병합하기
    /// </summary>
    /// <param name="sourceArrayArray">소스 배열 배열</param>
    /// <returns>병합 바이트 배열</returns>
    private static byte[] Merge(params byte[][] sourceArrayArray)
    {
        int targetArrayLength = 0;

        foreach(byte[] sourceArray in sourceArrayArray)
        {
            targetArrayLength += sourceArray.Length;
        }

        byte[] targetArray = new byte[targetArrayLength];

        int copyIndex = 0;

        foreach(byte[] sourceArray in sourceArrayArray)
        {
            int sourceArrayLength = sourceArray.Length;

            Array.Copy(sourceArray, 0, targetArray, copyIndex, sourceArrayLength);

            copyIndex += sourceArrayLength;
        }

        return targetArray;
    }

    #endregion
    #region 배열 출력하기 - PrintArray(sourceArray)

    /// <summary>
    /// 배열 출력하기
    /// </summary>
    /// <param name="sourceArray">소스 배열</param>
    private static void PrintArray(byte[] sourceArray)
    {
        foreach(byte source in sourceArray)
        {
            Console.Write($"{source} ");
        }
    }

    #endregion

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

    /// <summary>
    /// 프로그램 시작하기
    /// </summary>
    private static void Main()
    {
        byte[] sourceArray1 = new byte[] { 10, 20 };
        byte[] sourceArray2 = new byte[] { 30, 40, 50 };
        byte[] sourceArray3 = new byte[] { 60, 70 };

        byte[] targetArray = Merge(sourceArray1, sourceArray2, sourceArray3);

        Console.Write("소스 배열 1 : ");
        PrintArray(sourceArray1);
        Console.WriteLine();

        Console.Write("소스 배열 2 : ");
        PrintArray(sourceArray2);
        Console.WriteLine();

        Console.Write("소스 배열 3 : ");
        PrintArray(sourceArray3);
        Console.WriteLine();

        Console.Write("병합 배열   : ");
        PrintArray(targetArray);
        Console.WriteLine();
    }

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

댓글을 달아 주세요