ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Combine

Combines parts of 2 byte arrays

Source

//.Net Framework, .Net Compact Framework, Silverlight
public static byte[] Combine(this byte[] src1, int offset1, int count1, byte[] src2, int offset2, int count2) {
    byte[] arr = new byte[count1 + count2];
    for (int i = 0; i < count1; i++)
        arr[i] = src1[offset1 + i];
    for (int i = 0; i < count2; i++)
        arr[count1 + i] = src2[offset2 + i];
    return arr;
}

//.Net Micro Framework
public static byte[] Combine(this byte[] src1, int offset1, int count1, byte[] src2, int offset2, int count2) {
    return Microsoft.SPOT.Hardware.Utility.CombineArrays(src1, offset1, count1, src2, offset2, count2);
}

Example

byte[] arr1 = { 0x01, 0x02, 0x03, 0x04 };
byte[] arr2 = { 0x05, 0x06, 0x07, 0x08 };

byte[] arr3 = arr1.Combine(1, 3, arr2, 2, 2);
//arr3 should be { 0x02, 0x03, 0x04, 0x07, 0x08 }

Author: Linquize

Submitted on: 16 mei 2010

Language: C#

Type: System.Array

Views: 5209