Adding byte to byte array

There are two methods. either to create a new array or resize the existing array;

To resize existing array, do this;

Array.Resize(ref fileBytesArray, fileBytesArray.Length + 1);

To create a new array from existing one and resize, do this;

bArray = AddByteToArray(bArray,  newByte);

Here is the method;

public byte[] AddByteToArray(byte[] bArray, byte newByte)
{
    byte[] newArray = new byte[bArray.Length + 1];
    bArray.CopyTo(newArray, 1);
    newArray[0] = newByte;
    return newArray;
}

Reference

c# how to add byte to byte array

FavoriteLoadingAdd to favorites

RECENT POSTS


Categories



Tags

ADO ai angular asian asp.net asp.net core azure ACA azure administration azure app services Azure Cloud Architect Azure Key Vault Azure Storage Blazor WebAssembly BLOB bootstrap c# css datatables design pattern docker excel framework Git HTML JavaScript jQuery json knockout lab LINQ linux power bi powershell REST API smart home SQL Agent SQL server SSIS SSL SVG Icon typescript visual studio Web API window os wordpress


ARCHIVE


DISCLAIMER