Skip to content

ArrayExtensions Class

Allocation-explicit array helpers: each operation returns a freshly allocated array sized to the result. Prefer these over LINQ when the caller needs a concrete T[] without an extra ToArray() step, or when copying byte buffers via System.Buffer.BlockCopy(System.Array,System.Int32,System.Array,System.Int32,System.Int32) matters.

C#
public static class ArrayExtensions

Inheritance System.Object → ArrayExtensions

Methods

ArrayExtensions.Append<T>(this T[], T) Method

Appends a value to the end of an array.

C#
public static T[] Append<T>(this T[] array, T value);

Type parameters

T

The type of the elements in the array.

Parameters

array T[]

The array to append to.

value T

The value to append.

Returns

T[]
A new array with the value appended.

Remarks

This method creates a new array with a size larger by one than the original array, copies all elements from the original array, and adds the specified value at the end.

ArrayExtensions.Concat(byte[][]) Method

Concatenates multiple byte arrays into a single array.

C#
public static byte[] Concat(params byte[][] arrays);

Parameters

arrays System.Byte[][]

The arrays to concatenate.

Returns

System.Byte[]
A new array containing all input arrays concatenated in order.

Remarks

Uses Buffer.BlockCopy for efficient byte-level copying. Returns empty array if no arrays are provided.

ArrayExtensions.Concat(this byte[], byte[]) Method

Concatenates two byte arrays into a single array.

C#
public static byte[] Concat(this byte[] first, byte[] second);

Parameters

first System.Byte[]

The first array.

second System.Byte[]

The second array.

Returns

System.Byte[]
A new array containing all elements from both arrays in order.

Remarks

Uses Buffer.BlockCopy for efficient byte-level copying.

ArrayExtensions.Prepend<T>(this T[], T) Method

Prepends a value to the beginning of an array.

C#
public static T[] Prepend<T>(this T[] array, T value);

Type parameters

T

The type of the elements in the array.

Parameters

array T[]

The array to prepend to.

value T

The value to prepend.

Returns

T[]
A new array with the value prepended.

Remarks

This method creates a new array with a size larger by one than the original array, copies all elements from the original array starting from the second position, and adds the specified value at the beginning.