다음을 통해 공유


Buffer.BlockCopy(Array, Int32, Array, Int32, Int32) 메서드

정의

특정 오프셋에서 시작하는 소스 배열에서 특정 오프셋에서 시작하는 대상 배열로 지정된 바이트 수를 복사합니다.

public:
 static void BlockCopy(Array ^ src, int srcOffset, Array ^ dst, int dstOffset, int count);
public static void BlockCopy (Array src, int srcOffset, Array dst, int dstOffset, int count);
static member BlockCopy : Array * int * Array * int * int -> unit
Public Shared Sub BlockCopy (src As Array, srcOffset As Integer, dst As Array, dstOffset As Integer, count As Integer)

매개 변수

src
Array

소스 버퍼입니다.

srcOffset
Int32

src에 대한 바이트 오프셋입니다(0부터 시작).

dst
Array

대상 버퍼입니다.

dstOffset
Int32

dst에 대한 바이트 오프셋입니다(0부터 시작).

count
Int32

복사할 바이트 수입니다.

예외

src 또는 dstnull인 경우

src 또는 dst가 기본 형식의 배열이 아닌 경우

또는 src의 바이트 수가 srcOffsetcount를 더한 값보다 작은 경우

또는 dst의 바이트 수가 dstOffsetcount를 더한 값보다 작은 경우

srcOffset, dstOffset 또는 count가 0 미만입니다.

예제

다음 예제에서는 메서드를 사용하여 BlockCopy 배열 영역을 복사합니다. 각 BlockCopy 작업에 대해 원본 및 대상 배열을 값 배열과 바이트 시퀀스로 나열합니다. 이 예제에서는 메서드를 BlockCopy 사용할 때 시스템의 엔디언을 고려하는 것이 중요하다는 것을 보여 줍니다. Windows 시스템은 little-endian이므로 기본 데이터 형식 값의 하위 바이트가 상위 바이트보다 우선합니다.

using namespace System;

// Display the individual bytes in the array in hexadecimal.
void DisplayArray(System::Array^ arr, String^ name)
{
   Console::WindowWidth = 120;
   Console::Write("{0,11}:", name);
   for (int ctr = 0; ctr < arr->Length; ctr++)
   {
      array<Byte>^ bytes;
      if (arr->GetType() == array<Int64>::typeid)      
         bytes = BitConverter::GetBytes((Int64) arr->GetValue(ctr));
      else
         bytes = BitConverter::GetBytes((Int16) arr->GetValue(ctr));

      for each (Byte byteValue in bytes)
         Console::Write(" {0:X2}", byteValue);
   }
   Console::WriteLine();
}

// Display the individual array element values in hexadecimal.
void DisplayArrayValues(Array^ arr, String^ name)
{
   // Get the length of one element in the array.
   int elementLength = Buffer::ByteLength(arr) / arr->Length;
   String^ formatString = String::Format(" {{0:X{0}}}", 2 * elementLength);
   Console::Write( "{0,11}:", name);
   for (int ctr = 0; ctr < arr->Length; ctr++)
      Console::Write(formatString, arr->GetValue(ctr));

   Console::WriteLine();
}

void main()
{
   // These are the source and destination arrays for BlockCopy.
   array<Int16>^ src = gcnew array<Int16> { 258, 259, 260, 261, 262, 263, 264, 
                                            265, 266, 267, 268, 269, 270 };
   array<Int64>^ dest = gcnew array<Int64> { 17, 18, 19, 20 };

   // Display the initial value of the arrays in memory.
   Console::WriteLine( "Initial values of arrays:");
   Console::WriteLine("   Array values as Bytes:");
   DisplayArray(src, "src" );
   DisplayArray(dest, "dest");
   Console::WriteLine("   Array values:");
   DisplayArrayValues(src, "src");
   DisplayArrayValues(dest, "dest");
   Console::WriteLine();

   // Copy bytes 5-10 from source to index 7 in destination and display the result.
   Buffer::BlockCopy(src, 5, dest, 7, 6);
   Console::WriteLine("Buffer::BlockCopy(src, 5, dest, 7, 6 )");
   Console::WriteLine("   Array values as Bytes:");
   DisplayArray(src, "src");
   DisplayArray(dest, "dest");
   Console::WriteLine("   Array values:");
   DisplayArrayValues(src, "src");
   DisplayArrayValues(dest, "dest");
   Console::WriteLine();

   // Copy bytes 16-20 from source to index 22 in destination and display the result. 
   Buffer::BlockCopy(src, 16, dest, 22, 5);
   Console::WriteLine("Buffer.BlockCopy(src, 16, dest, 22, 5)");
   Console::WriteLine("   Array values as Bytes:");
   DisplayArray(src, "src");
   DisplayArray(dest, "dest");
   Console::WriteLine("   Array values:");
   DisplayArrayValues(src, "src");
   DisplayArrayValues(dest, "dest");
   Console::WriteLine();

   // Copy overlapping range of bytes 4-10 to index 5 in source.
   Buffer::BlockCopy(src, 4, src, 5, 7 );
   Console::WriteLine("Buffer.BlockCopy( src, 4, src, 5, 7)");
   Console::WriteLine("   Array values as Bytes:");
   DisplayArray(src, "src");
   DisplayArray(dest, "dest");
   Console::WriteLine("   Array values:");
   DisplayArrayValues(src, "src");
   DisplayArrayValues(dest, "dest");
   Console::WriteLine();

   // Copy overlapping range of bytes 16-22 to index 15 in source. 
   Buffer::BlockCopy(src, 16, src, 15, 7);
   Console::WriteLine("Buffer.BlockCopy( src, 16, src, 15, 7)");
   Console::WriteLine("   Array values as Bytes:");
   DisplayArray(src, "src");
   DisplayArray(dest, "dest");
   Console::WriteLine("   Array values:");
   DisplayArrayValues(src, "src");
}
// The example displays the following output:
//    Initial values of arrays:
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0000000000000011 0000000000000012 0000000000000013 0000000000000014
//    
//    Buffer.BlockCopy(src, 5, dest, 7, 6 )
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 0000000000000013 0000000000000014
//    
//    Buffer.BlockCopy(src, 16, dest, 22, 5)
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
//    
//    Buffer.BlockCopy( src, 4, src, 5, 7)
//       Array values as Bytes:
//            src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0404 0501 0601 0701 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
//    
//    Buffer.BlockCopy( src, 16, src, 15, 7)
//       Array values as Bytes:
//            src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 0A 01 0B 01 0C 01 0D 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0404 0501 0601 0701 0108 0A09 0B01 0C01 0D01 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
using System;

class Example
{
    // Display the individual bytes in the array in hexadecimal.
    public static void DisplayArray(Array arr, string name)
    {
        Console.WindowWidth = 120;
        Console.Write("{0,11}:", name);
        for (int ctr = 0; ctr < arr.Length; ctr++)
        {
            byte[] bytes;
            if (arr is long[])
               bytes = BitConverter.GetBytes((long) arr.GetValue(ctr));
            else
               bytes = BitConverter.GetBytes((short) arr.GetValue(ctr));

            foreach (byte byteValue in bytes)
               Console.Write(" {0:X2}", byteValue);
        }
        Console.WriteLine();
    }

    // Display the individual array element values in hexadecimal.
    public static void DisplayArrayValues(Array arr, string name)
    {
        // Get the length of one element in the array.
        int elementLength = Buffer.ByteLength(arr) / arr.Length;
        string formatString = String.Format(" {{0:X{0}}}", 2 * elementLength);
        Console.Write( "{0,11}:", name);
        for (int ctr = 0; ctr < arr.Length; ctr++)
            Console.Write(formatString, arr.GetValue(ctr));

        Console.WriteLine();
    }

    public static void Main( )
    {
        // These are the source and destination arrays for BlockCopy.
        short[] src  = { 258, 259, 260, 261, 262, 263, 264,
                          265, 266, 267, 268, 269, 270 };
        long[] dest = { 17, 18, 19, 20 };

        // Display the initial value of the arrays in memory.
        Console.WriteLine( "Initial values of arrays:");
        Console.WriteLine("   Array values as Bytes:");
        DisplayArray(src, "src" );
        DisplayArray(dest, "dest");
        Console.WriteLine("   Array values:");
        DisplayArrayValues(src, "src");
        DisplayArrayValues(dest, "dest");
        Console.WriteLine();

        // Copy bytes 5-10 from source to index 7 in destination and display the result.
        Buffer.BlockCopy(src, 5, dest, 7, 6);
        Console.WriteLine("Buffer.BlockCopy(src, 5, dest, 7, 6 )");
        Console.WriteLine("   Array values as Bytes:");
        DisplayArray(src, "src");
        DisplayArray(dest, "dest");
        Console.WriteLine("   Array values:");
        DisplayArrayValues(src, "src");
        DisplayArrayValues(dest, "dest");
        Console.WriteLine();

        // Copy bytes 16-20 from source to index 22 in destination and display the result.
        Buffer.BlockCopy(src, 16, dest, 22, 5);
        Console.WriteLine("Buffer.BlockCopy(src, 16, dest, 22, 5)");
        Console.WriteLine("   Array values as Bytes:");
        DisplayArray(src, "src");
        DisplayArray(dest, "dest");
        Console.WriteLine("   Array values:");
        DisplayArrayValues(src, "src");
        DisplayArrayValues(dest, "dest");
        Console.WriteLine();

        // Copy overlapping range of bytes 4-10 to index 5 in source.
        Buffer.BlockCopy(src, 4, src, 5, 7 );
        Console.WriteLine("Buffer.BlockCopy( src, 4, src, 5, 7)");
        Console.WriteLine("   Array values as Bytes:");
        DisplayArray(src, "src");
        DisplayArray(dest, "dest");
        Console.WriteLine("   Array values:");
        DisplayArrayValues(src, "src");
        DisplayArrayValues(dest, "dest");
        Console.WriteLine();

        // Copy overlapping range of bytes 16-22 to index 15 in source.
        Buffer.BlockCopy(src, 16, src, 15, 7);
        Console.WriteLine("Buffer.BlockCopy( src, 16, src, 15, 7)");
        Console.WriteLine("   Array values as Bytes:");
        DisplayArray(src, "src");
        DisplayArray(dest, "dest");
        Console.WriteLine("   Array values:");
        DisplayArrayValues(src, "src");
        DisplayArrayValues(dest, "dest");
    }
}
// The example displays the following output:
//    Initial values of arrays:
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0000000000000011 0000000000000012 0000000000000013 0000000000000014
//
//    Buffer.BlockCopy(src, 5, dest, 7, 6 )
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 0000000000000013 0000000000000014
//
//    Buffer.BlockCopy(src, 16, dest, 22, 5)
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
//
//    Buffer.BlockCopy( src, 4, src, 5, 7)
//       Array values as Bytes:
//            src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0404 0501 0601 0701 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
//
//    Buffer.BlockCopy( src, 16, src, 15, 7)
//       Array values as Bytes:
//            src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 0A 01 0B 01 0C 01 0D 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0404 0501 0601 0701 0108 0A09 0B01 0C01 0D01 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
open System

// Display the individual bytes in the array in hexadecimal.
let displayArray (arr: 'a []) (name: string) =
    Console.WindowWidth <- 120
    printf $"%11s{name}:"
    for i = 0 to arr.Length - 1 do
        let bytes =
            match box arr with 
            | :? array<int64> ->
                BitConverter.GetBytes(box arr[i] :?> int64)
            | _ ->
                BitConverter.GetBytes(box arr[i] :?> int16)
        for byteValue in bytes do
            printf $" %02X{byteValue}"
    printfn ""

// Display the individual array element values in hexadecimal.
let inline displayArrayValues (arr: ^a []) name =
    // Get the length of one element in the array.
    let elementLength = Buffer.ByteLength arr / arr.Length
    printf $"%11s{name}:"
    for value in arr do
        printf " %0*X" (2 * elementLength) value 
    printfn ""

// These are the source and destination arrays for BlockCopy.
let src =
    [| 258s; 259s; 260s; 261s; 262s; 263s; 264s
       265s; 266s; 267s; 268s; 269s; 270s |]

let dest = 
    [| 17L; 18L; 19L; 20L |]

// Display the initial value of the arrays in memory.
printfn "Initial values of arrays:"
printfn "   Array values as Bytes:"
displayArray src "src"
displayArray dest "dest"
printfn "   Array values:"
displayArrayValues src "src"
displayArrayValues dest "dest"
printfn ""

// Copy bytes 5-10 from source to index 7 in destination and display the result.
Buffer.BlockCopy(src, 5, dest, 7, 6)
printfn "Buffer.BlockCopy(src, 5, dest, 7, 6 )"
printfn "   Array values as Bytes:"
displayArray src "src"
displayArray dest "dest"
printfn "   Array values:"
displayArrayValues src "src"
displayArrayValues dest "dest"
printfn ""

// Copy bytes 16-20 from source to index 22 in destination and display the result.
Buffer.BlockCopy(src, 16, dest, 22, 5)
printfn "Buffer.BlockCopy(src, 16, dest, 22, 5)"
printfn "   Array values as Bytes:"
displayArray src "src"
displayArray dest "dest"
printfn "   Array values:"
displayArrayValues src "src"
displayArrayValues dest "dest"
printfn ""

// Copy overlapping range of bytes 4-10 to index 5 in source.
Buffer.BlockCopy(src, 4, src, 5, 7)
printfn "Buffer.BlockCopy(src, 4, src, 5, 7)"
printfn "   Array values as Bytes:"
displayArray src "src"
displayArray dest "dest"
printfn "   Array values:"
displayArrayValues src "src"
displayArrayValues dest "dest"
printfn ""

// Copy overlapping range of bytes 16-22 to index 15 in source.
Buffer.BlockCopy(src, 16, src, 15, 7)
printfn "Buffer.BlockCopy(src, 16, src, 15, 7)"
printfn "   Array values as Bytes:"
displayArray src "src"
displayArray dest "dest"
printfn "   Array values:"
displayArrayValues src "src"
displayArrayValues dest "dest"


// The example displays the following output:
//    Initial values of arrays:
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0000000000000011 0000000000000012 0000000000000013 0000000000000014
//
//    Buffer.BlockCopy(src, 5, dest, 7, 6 )
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 0000000000000013 0000000000000014
//
//    Buffer.BlockCopy(src, 16, dest, 22, 5)
//       Array values as Bytes:
//            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
//
//    Buffer.BlockCopy(src, 4, src, 5, 7)
//       Array values as Bytes:
//            src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0404 0501 0601 0701 0108 0109 010A 010B 010C 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
//
//    Buffer.BlockCopy(src, 16, src, 15, 7)
//       Array values as Bytes:
//            src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 0A 01 0B 01 0C 01 0D 0D 01 0E 01
//           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
//       Array values:
//            src: 0102 0103 0404 0501 0601 0701 0108 0A09 0B01 0C01 0D01 010D 010E
//           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
Module Example
    ' Display the individual bytes in the array in hexadecimal.
    Sub DisplayArray(arr As Array, name As String)
        Console.Write("{0,11}:", name)
        For ctr As Integer = 0 to arr.Length - 1
            Dim bytes() As Byte = BitConverter.GetBytes(arr(ctr))
            For Each byteValue As Byte In bytes
               Console.Write(" {0:X2}", byteValue)
            Next
        Next
        Console.WriteLine()
    End Sub

    ' Display the individual array element values in hexadecimal.
    Sub DisplayArrayValues(arr As Array, name As String)
       ' Get the length of one element in the array.
       Dim elementLength As Integer = Buffer.ByteLength(arr) / arr.Length
       Dim formatString As String = String.Format(" {{0:X{0}}}", 2 * elementLength)
       Console.Write("{0,11}:", name)
       For ctr As Integer = 0 to arr.Length - 1
         Console.Write(formatString, arr(ctr))
       Next
       Console.WriteLine()  
    End Sub
    
    Sub Main()
       Console.WindowWidth = 120
        ' These are source and destination arrays for BlockCopy.
        Dim src()  As Short = { 258, 259, 260, 261, 262, 263, 264, _
                                 265, 266, 267, 268, 269, 270 }
        Dim dest() As Long = { 17, 18, 19, 20 }

        ' Display the initial value of the arrays in memory.
        Console.WriteLine( "Initial values of arrays:")
        Console.WriteLine("   Array values as Bytes:") 
        DisplayArray(src, "src" )
        DisplayArray(dest, "dest" )
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
        Console.WriteLine()

        ' Copy bytes 5-10 from source to index 7 in destination and display the result.
        Buffer.BlockCopy( src, 5, dest, 7, 6 )
        Console.WriteLine("Buffer.BlockCopy(src, 5, dest, 7, 6 )")
        Console.WriteLine("   Array values as Bytes:")
        DisplayArray(src, "src")
        DisplayArray(dest, "dest")
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
        Console.WriteLine()
        
        ' Copy bytes 16-20 from source to index 22 in destination and display the result. 
        Buffer.BlockCopy( src, 16, dest, 22, 5 )
        Console.WriteLine("Buffer.BlockCopy(src, 16, dest, 22, 5)")
        Console.WriteLine("   Array values as Bytes:")
        DisplayArray(src, "src")
        DisplayArray(dest, "dest")
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
        Console.WriteLine()
         
        ' Copy overlapping range of bytes 4-10 to index 5 in source.
        Buffer.BlockCopy( src, 4, src, 5, 7 )
        Console.WriteLine("Buffer.BlockCopy( src, 4, src, 5, 7)")
        Console.WriteLine("   Array values as Bytes:")
        DisplayArray(src, "src")
        DisplayArray(dest, "dest")
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
        Console.WriteLine()
        
        ' Copy overlapping range of bytes 16-22 to index 15 in source. 
        Buffer.BlockCopy(src, 16, src, 15, 7)
        Console.WriteLine("Buffer.BlockCopy( src, 16, src, 15, 7)")
        Console.WriteLine("   Array values as Bytes:")
        DisplayArray(src, "src")
        DisplayArray(dest, "dest")
        Console.WriteLine("   Array values:")
        DisplayArrayValues(src, "src")
        DisplayArrayValues(dest, "dest")
    End Sub 
End Module 
' This example displays the following output:
'    Initial values of arrays:
'       Array values as Bytes:
'            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
'           dest: 11 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
'       Array values:
'            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
'           dest: 0000000000000011 0000000000000012 0000000000000013 0000000000000014
'    
'    Buffer.BlockCopy(src, 5, dest, 7, 6 )
'       Array values as Bytes:
'            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
'           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00
'       Array values:
'            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
'           dest: 0100000000000011 0000000701060105 0000000000000013 0000000000000014
'    
'    Buffer.BlockCopy(src, 16, dest, 22, 5)
'       Array values as Bytes:
'            src: 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
'           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
'       Array values:
'            src: 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B 010C 010D 010E
'           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
'    
'    Buffer.BlockCopy( src, 4, src, 5, 7)
'       Array values as Bytes:
'            src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01
'           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
'       Array values:
'            src: 0102 0103 0404 0501 0601 0701 0108 0109 010A 010B 010C 010D 010E
'           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B
'    
'    Buffer.BlockCopy( src, 16, src, 15, 7)
'       Array values as Bytes:
'            src: 02 01 03 01 04 04 01 05 01 06 01 07 08 01 09 0A 01 0B 01 0C 01 0D 0D 01 0E 01
'           dest: 11 00 00 00 00 00 00 01 05 01 06 01 07 00 00 00 13 00 00 00 00 00 0A 01 0B 01 0C 00 00 00 00 00
'       Array values:
'            src: 0102 0103 0404 0501 0601 0701 0108 0A09 0B01 0C01 0D01 010D 010E
'           dest: 0100000000000011 0000000701060105 010A000000000013 00000000000C010B

설명

이 메서드는 바이트를 dstOffset``dst``srcOffset``src복사합니다.count dstOffset 둘 다 srcOffset 0부터 시작하는 것입니다. 즉, 각 버퍼의 첫 번째 바이트는 위치 1이 아니라 위치 0에 있습니다.

이 메서드는 BlockCopy 인덱스 또는 상한 및 하한과 같은 구문을 프로그래밍하지 않고 메모리에 오프셋을 사용하여 매개 변수 배열의 바이트에 src 액세스합니다. 예를 들어, 애플리케이션의 프로그래밍 언어에서 선언 하는 경우는 Int32 인 0부터 시작-50, 배열 및 배열 및 오프셋을 5로 전달 된 BlockCopy 메서드, 메서드에 액세스 하는 첫 번째 배열 요소는 두 번째 -49 인덱스에는 배열의 요소입니다. 또한는 바이트 배열 요소의-49 액세스 하는 먼저 종속 애플리케이션을 실행 하는 컴퓨터의 엔디언.

이름에서 알 수 있듯이 메서드는 BlockCopy 바이트 블록을 한 번에 하나씩 복사하는 대신 전체 바이트 블록을 복사합니다. 따라서 동일한 배열을 dst 참조하고 -1의 + count srcOffset범위가 -1의count + dstOffset 범위와 겹치면 src 대상에 복사되기 전에 겹치는 바이트의 값을 덮어쓰지 않습니다. 다음 예제에서는 명명 arr 된 배열의 바이트 0-16 값이 12-28바이트로 복사됩니다. 범위가 겹치더라도 원본 바이트의 값이 성공적으로 복사됩니다.

const int INT_SIZE = 4;
array<Int32>^ arr = gcnew array<Int32> { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
Buffer::BlockCopy(arr, 0 * INT_SIZE, arr, 3 * INT_SIZE, 4 * INT_SIZE);
for each (int value in arr)
   Console::Write("{0}  ", value);
// The example displays the following output:
//       2  4  6  2  4  6  8  16  18  20
const int INT_SIZE = 4;
int[] arr = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
Buffer.BlockCopy(arr, 0 * INT_SIZE, arr, 3 * INT_SIZE, 4 * INT_SIZE);
foreach (int value in arr)
   Console.Write("{0}  ", value);
// The example displays the following output:
//       2  4  6  2  4  6  8  16  18  20
let intSize = 4
let arr = [| 2; 4; 6; 8; 10; 12; 14; 16; 18; 20 |]
Buffer.BlockCopy(arr, 0 * intSize, arr, 3 * intSize, 4 * intSize)
for value in arr do
    printf $"{value}  "

// The example displays the following output:
//       2  4  6  2  4  6  8  16  18  20
Const INT_SIZE As Integer = 4
Dim arr() As Integer = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }
Buffer.BlockCopy(arr, 0 * INT_SIZE, arr, 3 * INT_SIZE, 4 * INT_SIZE)
For Each value As Integer In arr
   Console.Write("{0}  ", value)
Next
' The example displays the following output:
'       2  4  6  2  4  6  8  16  18  20

다음 예제에서는 명명 arr 된 배열의 바이트 12-28 값이 바이트 0-16으로 복사됩니다. 마찬가지로 범위가 겹치더라도 원본 바이트의 값이 성공적으로 복사됩니다.

const int INT_SIZE = 4;
array<Int32>^ arr = gcnew array<Int32> { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
Buffer::BlockCopy(arr, 3 * INT_SIZE, arr, 0 * INT_SIZE, 4 * INT_SIZE);
for each (int value in arr)
   Console::Write("{0}  ", value);
// The example displays the following output:
//       8  10  12  14  10  12  14  16  18  20
const int INT_SIZE = 4;
int[] arr = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
Buffer.BlockCopy(arr, 3 * INT_SIZE, arr, 0 * INT_SIZE, 4 * INT_SIZE);
foreach (int value in arr)
   Console.Write("{0}  ", value);
// The example displays the following output:
//       8  10  12  14  10  12  14  16  18  20
let intSize = 4
let arr = [| 2; 4; 6; 8; 10; 12; 14; 16; 18; 20 |]
Buffer.BlockCopy(arr, 3 * intSize, arr, 0 * intSize, 4 * intSize)
for value in arr do
    printf $"{value}  "

// The example displays the following output:
//       8  10  12  14  10  12  14  16  18  20
Const INT_SIZE As Integer = 4
Dim arr() As Integer = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }
Buffer.BlockCopy(arr, 3 * INT_SIZE, arr, 0 * INT_SIZE, 4 * INT_SIZE)
For Each value As Integer In arr
   Console.Write("{0}  ", value)
Next
' The example displays the following output:
'       8  10  12  14  10  12  14  16  18  20

적용 대상