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

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            int[] buf = new int[5];

            Buffer.BlockCopy(arr, 0, buf, 0, 3 * sizeof(int));

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

/*
run:

1
2
3
0
0

*/

 



answered Jan 6, 2017 by avibootz
...