ArrayExtensionsCastTFrom, TTo(TFrom) Method

Reinterprets the specified array by returning a CastArrayTFrom, TTo struct, so its element type is cast from TFrom to TTo. No heap allocation occurs when using this method.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public static CastArray<TFrom, TTo> Cast<TFrom, TTo>(
	this TFrom[]? array
)
where TFrom : struct, new()
where TTo : struct, new()

Parameters

array  TFrom
The array to create the CastArrayTFrom, TTo from.

Type Parameters

TFrom
The actual element type of the specified array.
TTo
The reinterpreted element type after casting.

Return Value

CastArrayTFrom, TTo
A CastArrayTFrom, TTo instance for the specified array.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type TFrom. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

If the size of TTo cannot be divided by the size of TFrom, then the cast result may not cover the whole original array to prevent exceeding beyond the available buffer.

See Also