Array - BlockCopy

Copies a specified number of bytes from a source array starting at a particular offset to a destination array starting at a particular offset.

Try it

public static void Main()
{
	const int INT_SIZE = 4;
	int[] sourceArray = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
	
	 // Displays the values of the Array.
    Console.WriteLine( "Original values:" );
    PrintValues(sourceArray);

	// C# Extension Method: Buffer - BlockCopy
    sourceArray.BlockCopy(3 * INT_SIZE, sourceArray, 0 * INT_SIZE, 4 * INT_SIZE);

	Console.WriteLine( "Values after calling BlockCopy method:" );
    PrintValues(sourceArray);
}

public static void PrintValues(Array myArr)
{
    int i = 0;
    int cols = myArr.GetLength(myArr.Rank - 1);
    foreach (object o in myArr)
    {
        if ( i < cols )
        {
            i++;
        }
        else
        {
            Console.WriteLine();
            i = 1;
        }
        Console.Write( "\t{0}", o);
    }
    Console.WriteLine();
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     Copies a specified number of bytes from a source array starting at a particular offset to a destination array
    ///     starting at a particular offset.
    /// </summary>
    /// <param name="src">The source buffer.</param>
    /// <param name="srcOffset">The zero-based byte offset into .</param>
    /// <param name="dst">The destination buffer.</param>
    /// <param name="dstOffset">The zero-based byte offset into .</param>
    /// <param name="count">The number of bytes to copy.</param>
    public static void BlockCopy(this Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
    {
        Buffer.BlockCopy(src, srcOffset, dst, dstOffset, count);
    }
}