Append byte to byte array - CSharp System

CSharp examples for System:Byte Array

Description

Append byte to byte array

Demo Code


using System.Runtime.InteropServices;
using System.Collections.Generic;
using System;//from  w w w  .j  a  va2  s .c  om

public class Main{
        public static byte[] Append(this byte[] data, byte toAppend) {
            var buffer = new byte[data.Length + 1];
            data.CopyTo(buffer, 0);
            buffer[buffer.Length - 1] = toAppend;
            return buffer;
        }
        public static byte[] Append(this byte[] data, byte[] toAppend) {
            var buffer = new byte[data.Length + toAppend.Length];
            data.CopyTo(buffer, 0);
            toAppend.CopyTo(buffer, data.Length);
            return buffer;
        }
}

Related Tutorials