How to use Buffer.BlockCopy() to range of bytes from one array to another in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] arr = new byte[6];

            arr[0] = 1;
            arr[1] = 2;
            arr[2] = 3;
            arr[3] = 4;
            arr[4] = 5;
            arr[5] = 6;

            byte[] buf = new byte[8];

            Buffer.BlockCopy(arr, 0, buf, 0, 5);

            for (int i = 0; i < buf.Length; i++)
                Console.WriteLine(buf[i]);
        }
    }
}

/*
run:

1
2
3
4
5
0
0
0

*/

 



answered Jan 6, 2017 by avibootz
...